#! /bin/sh
#
#       @(#)postremove	1.7     96/12/10 (c) SMCC Inc.
#

PATH="/usr/bin:/usr/sbin:${PATH}"
export PATH

#
# Driver info
#
DRV="dg2"
DRVALIAS="TRTC,dg2"

#
# Select the correct rem_drv options to execute.
# Only attempt to unload the driver on a running system. 
#
if [ "${BASEDIR}" = "/" ]; then
        REM_DRV="rem_drv"
else
        REM_DRV="rem_drv -b ${BASEDIR}"
fi

#
# Make sure rem_drv has *not* been previously executed
# before attempting to remove the driver.
#
grep "^${DRV} " ${BASEDIR}/etc/name_to_major > /dev/null 2>&1
if [ $? -eq 0 ]; then
	${REM_DRV} ${DRV}
	if [ $? -ne 0 ]; then
		echo "\nFailed rem_drv!\n" >&2
		exit 1
	fi
fi

#
# Clean /dev/fb* and /dev/fbs/* links to driver
# These are created by devlinks.
# rem_drv does not know about them.
#
FBS=`ls -ld ${BASEDIR}/dev/fb* | fgrep fbs/${DRV} | awk '{print $9}'`
if [ "$FBS" != "" ]
then
        /bin/rm -f ${FBS}
fi
rm -f ${BASEDIR}/dev/fbs/${DRV}*

#
# Remove entries fomr /etc/path_to_inst
#
grep ${DRVALIAS} ${BASEDIR}/etc/path_to_inst >/dev/null 2>&1
if [ $? -eq 0 ]; then
        echo "## Remove entry from /etc/path_to_inst"
        grep -v ${DRVALIAS} ${BASEDIR}/etc/path_to_inst >/tmp/path_to_inst.$$
        mv /tmp/path_to_inst.$$ ${BASEDIR}/etc/path_to_inst
fi

exit 0

