#!/bin/sh
#
# Linux DGNC 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.

# Note, we do NOT create a dpa symlink during the install,
# so there is no check here to remove it.

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

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

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

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

# Remove UDEV rules file, if its still around.
if [ -f /etc/udev/rules.d/10-dgnc.rules ]
then
	rm -f /etc/udev/rules.d/10-dgnc.rules
fi

# Unload dgnc module if we can
if [ "`/sbin/lsmod | grep -c dgnc`" -gt "0" ]
then
	/sbin/rmmod dgnc
fi

# Remove the driver from the modules config file
if [ -f /etc/modules.conf ]
then
	# Make a backup copy of /etc/modules.conf
	cp /etc/modules.conf /etc/modules.conf.bak
	# remove lines from config file
	grep -v "dgnc" /etc/modules.conf > /etc/modules.conf.new
	mv /etc/modules.conf.new /etc/modules.conf
fi
