#!/bin/sh

# Paths:
HOTPLUGDIR=/etc/hotplug
PPPDIR=/etc/ppp

# Messages:
PWDMSG="Il se peut que les fichiers $PPPDIR/pap-secrets et\n$PPPDIR/chap-secrets contiennent encore un ou plusieurs\nmots de passe. Vous pouvez les supprimer manuellement.\n"
DELPWDMSG="Un login et mot de passe FreeAdsl ont t trouvs dans le fichier de configuration de ppp.\nVoulez-vous supprimer ce login et mot de passe ?\n[n]/o"


if [ -f $HOTPLUGDIR/usb.usermap.local ] ; then
	grep -v adiusb $HOTPLUGDIR/usb.usermap.local > $HOTPLUGDIR/usb.usermap.local.temp &&
	mv --reply=no $HOTPLUGDIR/usb.usermap.local $HOTPLUGDIR/usb.usermap.local.old &&
	mv -f $(HOTPLUGDIR)/usb.usermap.local.temp $HOTPLUGDIR/usb.usermap.local &&
	/usr/sbin/update-usb.usermap
else
	grep -v adiusb $HOTPLUGDIR/usb.usermap > $HOTPLUGDIR/usb.usermap.temp &&
	mv --reply=no $HOTPLUGDIR/usb.usermap $HOTPLUGDIR/usb.usermap.old &&
	mv -f $HOTPLUGDIR/usb.usermap.temp $HOTPLUGDIR/usb.usermap
fi
if grep -q adsl.inittab /etc/inittab ; then
	grep -v adsl.inittab /etc/inittab > /etc/inittab.temp &&
	mv --reply=no /etc/inittab /etc/inittab.old &&
	mv -f /etc/inittab.temp /etc/inittab &&
	/sbin/telinit Q
fi

umask 0077
DISPLAYMSG=0
DELPWD=1
if [ -f $PPPDIR/pap-secrets ] ; then
	if grep -q freeadsl $PPPDIR/pap-secrets ; then
		echo -en $DELPWDMSG
		read REP
		if [ -z $REP ]; then DELPWD=0; fi
		if [ ! $REP = "o" ]; then DELPWD=0; fi
		if [ $DELPWD = 1 ]; then
			grep -v freeadsl $PPPDIR/pap-secrets > $PPPDIR/pap-secrets.temp &&
			mv --reply=no $PPPDIR/pap-secrets $PPPDIR/pap-secrets.old &&
			mv -f $PPPDIR/pap-secrets.temp $PPPDIR/pap-secrets
		fi
	else
		DISPLAYMSG=1
	fi
fi
if [ -f $PPPDIR/chap-secrets ] ; then
	if grep -q freeadsl $PPPDIR/chap-secrets ; then
		if [ $DELPWD = 1 ]; then
			grep -v freeadsl $PPPDIR/chap-secrets > $PPPDIR/chap-secrets.temp &&
			mv --reply=no $PPPDIR/chap-secrets $PPPDIR/chap-secrets.old &&
			mv -f $PPPDIR/chap-secrets.temp $PPPDIR/chap-secrets
		fi
	else
		DISPLAYMSG=1
	fi
fi
if [ $DELPWD = 1 ]; then
	rm -f $PPPDIR/options.adsl
fi
if [ $DISPLAYMSG = 1 ] ; then
	echo "=============================================================="
	echo -e $PWDMSG
fi
