#! /bin/sh
#
# Copyright (c) 1991, by Sun Microsystems, Inc.
#
#

#
# Functions
#
killproc() {		# kill the named process(es)
	pid=`/usr/bin/ps -def |
	     /usr/bin/grep -v grep | grep $1 |
	     /usr/bin/awk '{print $2}'`
	[ "$pid" != "" ] && kill -HUP $pid
}

#
# Give up if /usr not mounted
#
if [ ! -d /usr/bin ]
then			# /usr not mounted
	exit
fi

PATH="/bin:/usr/ucb:/usr/bin:/etc"
export PATH

# echo "debug: BEGINNING OF PREREMOVE"

#
# Try and establish what was installed.
# There must be a better way to do this!!!
#
DO_PCNFSD=0
DO_MSG=0
DO_SLIP=0

pcnfsd_class=`echo "$CLASSES" | /usr/bin/grep pcpcnfsd`
msg_class=`echo "$CLASSES" | /usr/bin/grep pcmsg`
slip_class=`echo "$CLASSES" | /usr/bin/grep pcslip`

if [ "$pcnfsd_class" != "" ]
then
	DO_PCNFSD=1
fi

if [ "msg_class" != "" ]
then
	DO_MSG=1
fi

if [ "$slip_class" != "" ]
then
	DO_SLIP=1
fi

#
# Bring down any pcnfsd, msgserv processes that may be running.
#
pid1=`/usr/bin/ps -def | /usr/bin/grep -v grep | /usr/bin/grep rpc.pcnfsd |
/usr/bin/awk '{print $2}'`

pid2=`/usr/bin/ps -def | /usr/bin/grep -v grep | /usr/bin/grep msgserv |
/usr/bin/awk '{print $2}'`

if [ $DO_PCNFSD -eq 1 ]
then
	if [ "$pid1" != "" ]
	then
		echo ""
		echo "Bringing down rpc.pcnfsd process...."
		echo ""
		killproc rpc.pcnfsd
	fi
fi

if [ $DO_MSG -eq 1 ]
then
	if [ "$pid2" != "" ]
	then
		echo ""
		echo "Bringing down msgserv process...."
		echo ""
		killproc msgserv
	fi
fi

#
# Remove slip driver.
#
slid1=`/usr/sbin/modinfo | /usr/bin/grep 'sl (Serial Line IP'`
slid2=`cat /etc/name_to_major | /usr/bin/grep '^sl'`

if [ $DO_SLIP -eq 1 ]
then
	if [ "$slid1" != "" -o "$slid2" != "" ]
	then
		echo ""
		echo "Removing existing slip driver...."
		echo ""
		SAVEDIR=$BASEDIR
		BASEDIR=/	
		export BASEDIR
		/usr/sbin/rem_drv sl
		BASEDIR=$SAVEDIR
		export BASEDIR
	fi
fi

# echo "debug: END OF PREREMOVE"

exit 0
