#!/bin/sh
#
# Linux DGAP Pre UnInstall script.
# Should be run before a "make uninstall".
#
# 1) Will be called automagically by rpm -e.
# 2) Needs to be called manually for the tar.gz install
#    by doing a "make preuninstall"

echo "Running Pre UnInstall script..."


# Remove any symlinks the postinstall script might have made.
if [ -L /usr/bin/dpa ]
then
	if [ "`ls -l /usr/bin/dpa | grep -c dgap`" -gt "0" ]
	then
		rm -f /usr/bin/dpa
	fi
fi

if [ -L /usr/bin/ditty ]
then
	if [ "`ls -l /usr/bin/ditty | grep -c dgap`" -gt "0" ]
	then
		rm -f /usr/bin/ditty
	fi
fi

if [ -L /usr/bin/dinc ]
then
	if [ "`ls -l /usr/bin/dinc | grep -c dgap`" -gt "0" ]
	then
		rm -f /usr/bin/dinc
	fi
fi
  

# Finally, Unload dgap module if we can
#
# stop download daemon
pid=`ps -ef | grep dgapdl | awk '{print $2}'`
[ ! -z "$pid" ] && kill -1 ${pid} 2>/dev/null

# Wait for a second to let the daemon die.
sleep 1

if [ "`/sbin/lsmod | grep -c dgap`" -gt "0" ]
then
	/sbin/rmmod dgap
fi
