#!/bin/bash

. ./setvars

if [ -z "$1" ] || [ -z "$2" ] ; then
	echo "syntax: uninstOld \$MODULESDIR \$KERNELSRCDIR"
	exit 1
fi

# Paths:
#LMV=/lib/modules/`uname -r`
#USV=/usr/src/linux-`uname -r`
LMV=$1
USV=$2

# unload old driver
if lsmod | grep -q "adiusbadsl" ; then
	rmmod adiusbadsl
fi

# === distribution specific ===
if [ "$DISTRIB" = "Mandrake" ] && [ `expr $DISTVER = 9.1` == 1 ] ; then
	# 1.0.2cc5
	rpm -e adiusbadsl 2>/dev/null
	rm -f $LMV/kernel/drivers/usb/adiusbadsl.o
fi
if [ "$DISTRIB" = "Mandrake" ] && [ `expr $DISTVER = 9.2` == 1 ] ; then
	# 1.0.4
	rpm -e adiusbadsl 2>/dev/null
	echo "$LMV/kernel/3rdparty/adiusbadsl"
	rm -Rf $LMV/kernel/3rdparty/adiusbadsl
fi

# === < 1.0.4e ===
if grep -q adsl.inittab /etc/inittab ; then
	grep -v adsl.inittab /etc/inittab > /etc/inittab.temp
	if [ ! -e /etc/inittab.old ] ; then
		mv -f /etc/inittab /etc/inittab.old
	fi
	mv -f /etc/inittab.temp /etc/inittab
	RES="`whereis telinit | cut -d ':' -f2`"
	if [ ! -z "$RES" ] ; then
		telinit Q
	fi
fi
if [ -f /etc/hotplug/usb.usermap.local ] ; then
	grep -v adiusb /etc/hotplug/usb.usermap.local > /etc/hotplug/usb.usermap.local.temp &&
	mv -f /etc/hotplug/usb.usermap.local.temp /etc/hotplug/usb.usermap.local
fi
if [ -f /var/lock/subsys/adiusbadsl ] && [ -e /etc/init.d/adiusbadsl ] ; then
	/etc/init.d/adiusbadsl stop
fi
rm -f $LMV/usb/adiusbadsl.o &&
rm -f $LMV/kernel/drivers/usb/adiusbadsl.o &&
rm -f /usr/sbin/adsl.inittab &&
rm -f /etc/rc.d/init.d/adiusbadsl &&
rm -f /etc/rc.d/rc0.d/*adiusbadsl &&
rm -f /etc/rc.d/rc1.d/*adiusbadsl &&
rm -f /etc/rc.d/rc2.d/*adiusbadsl &&
rm -f /etc/rc.d/rc3.d/*adiusbadsl &&
rm -f /etc/rc.d/rc4.d/*adiusbadsl &&
rm -f /etc/rc.d/rc5.d/*adiusbadsl &&
rm -f /etc/rc.d/rc6.d/*adiusbadsl
rm -f /var/run/adiusbadsl

# === 1.0.4e ===
rm -Rf /etc/eagle-usb &&
rm -Rf /etc/analog &&
rm -f /usr/sbin/startadsl &&
rm -f /usr/sbin/stopadsl &&
rm -f /usr/sbin/startmire &&
rm -f /usr/sbin/eagleConfig &&
rm -Rf /usr/lib/hotplug/adiusbadsl &&
rm -f /etc/hotplug/usb/adiusbdsp &&
rm -f /etc/ppp/options.adsl &&
rm -f /etc/ppp/options.mire &&
rm -f /etc/eagleusb.conf

# === CVS ===
# unload current driver
if lsmod | grep -q "eagle-usb" ; then
	rmmod eagle-usb
fi


# one of these two lines should be removed when Makefile-2.4 will properly uninstall the module
#rm -f $LMV/kernel/misc/eagle-usb.o
#rm -f $LMV/misc/eagle-usb.o
#../driver/unloadModule
#cat $LMV/modules.usbmap | grep -v adiusb > $LMV/modules.usbmap
#rm -Rf $LMV/kernel/drivers/usb/adiusbadsl
#rm -Rf $USV/drivers/usb/adiusbadsl
#grep -v "options adiusbadsl" /etc/modules.conf > /etc/modules.conf.temp
#if [ ! -f /etc/modules.conf.old ] ; then
#	mv /etc/modules.conf /etc/modules.conf.old
#fi
#mv -f /etc/modules.conf.temp /etc/modules.conf
