#!/bin/sh
#
#ident "@(#)preremove	1.15 12/03/99 SMI"
#
# Copyright 1993 Sun Microsystems, Inc. All Rights Reserved
#

killlogd() {
	PID=`ps -ef |grep $OSILOGD |grep -v grep|awk '{ print $2 }'`
	if [ -n "$PID" ]; then
		kill -KILL  $PID 2>&1 >/dev/null
	fi
}

killnetd() {
	PID=`ps -ef |grep $OSINETD |grep -v grep|awk '{ print $2 }'`
	if [ -n "$PID" ]; then
		rm -f $NETDTMP  2>&1 >/dev/null
		kill -TERM $PID  >/dev/null
		#
		# wait until the daemon is really dead
		#
		while [ -n "$PID" ]; do
			PID=`ps -ef |grep $OSINETD |grep -v grep|awk '{ print $2 }'`
		done
	fi
}


# Exit codes for installation scripts 
e_ok=0      
e_fatal=1      # stop installation on this exit
e_warning=2    # Installation will go on. 
e_int=3        # Interrupted. Stop installation
e_reboot=10    # User must reboot after installation of all selected packages
e_rebootnow=20 # User must reboot right after installation of current package
               # To be added to one of the single-digit exit code above

# Trap interrupt
trap `exit $e_int` 15

#
DRVS="rk6tr"         # List of drivers 

REM_DRV="/usr/sbin/rem_drv"
NAME_DRV="/etc/name_to_major"
SPECIFIC="/dev/rk6tr"
NETDTMP="/tmp/osinetd.status"

OSILOGD=osilogd
OSINETD=osinetd


#
# ***   the /usr/sbin/add_drv script uses BASEDIR variable to
#       acces /etc/name_to_major.
#       We should redifined this variable to be independant of
#       the value used by pkgadd
#
BASEDIR=/ ; export BASEDIR

#
# Kill the daemon
#
killnetd
killlogd

for D in $DRVS; do
	if grep "^$D" $NAME_DRV 2>1 >/dev/null ; then
		echo "Removing $D driver ..."
		$REM_DRV $D
		#
		# We should not have to do this manually. The system (rem_drv)
		# should remove these files automatically (OS BUG?).
		# 
		rm -f /devices/pseudo/clone*:$D # for 1093 compatibility
		rm -f /dev/$D
	else
		echo "The $D driver is already removed"
	fi
done
#
# Remove Specific OSI Installation stuff
#
for I in $SPECIFIC; do
	if [ -c "$I" -o  -h $I ]; then
		rm -f $I
	fi
done

#
# Licensing
#


exit 0

# Happy End
exit $e_ok
