#! /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 PREINSTALL"

#
# Save copies of rpc.pcnfsd, msgserv if they haven't already saved it
#
if [ $DO_PCNFSD -eq 1 ]
then
	if [ -f /usr/lib/nfs/rpc.pcnfsd ] ;
	then
		if [ ! -f /usr/lib/nfs/rpc.pcnfsd.pre-pcnfs ] ;
		then
			echo ""
			echo "Saving existing rpc.pcnfsd as rpc.pcnfsd.pre-pcnfs...."
			echo ""
			cp /usr/lib/nfs/rpc.pcnfsd /usr/lib/nfs/rpc.pcnfsd.pre-pcnfs
		fi
	fi
fi

if [ $DO_MSG -eq 1 ]
then
	if [ -f /usr/lib/nfs/msgserv ] ;
	then
		if [ ! -f /usr/lib/nfs/msgserv.pre-pcnfs ] ;
		then
			echo ""
			echo "Saving existing msgserv as msgserv.pre-pcnfs...."
			echo ""
			cp /usr/lib/nfs/msgserv /usr/lib/nfs/msgserv.pre-pcnfs
		fi
	fi
fi


#
# Then 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 if necessary
#
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 PREINSTALL"

exit 0
