#!/bin/sh
#
# $Id: preinstall.sh,v 1.3 1995/06/21 15:27:51 lduncan Exp $
#
# stop volmgt (so that it can be patched)
#
# used for patches that need volmgt to stop before files are patched
# (must be used with postinstall that re-start volmgt)
#
# updates:
#   6/95	now using get_vold_pid() function
#   6/95	updated to skip stopping volmgt iff we are updating
#		a client
#
 
 
PID=""
get_vold_pid()
{
	# set global PID to that of vold (if found)
	PID=`/usr/bin/ps -e|/usr/bin/fgrep vold|/usr/bin/awk '{print $1}'`
}

#
# actual start of script
#

# if BASEDIR is unset, or is '/', then we are local (else exit)
: ${BASEDIR:='/'}
if [ "$BASEDIR" != '/' ] ; then
	# this update is for a client -- no need to stop volmgt
	exit 0
fi

# look for vold running -- if found then try to stop it
get_vold_pid
if [ ! -z "$PID" ] ;  then
 
        # found vold -- (try to) stop it
        if [ -f /etc/init.d/volmgt ] ; then
                /etc/init.d/volmgt stop
        else
                echo "Warning: can not find script to stop vold"
                echo " trying to stop in manually"
                /usr/bin/kill "$PID" 1>/dev/null 2>&1
        fi

	# wait (a while) to ensure it really stopped
	cnt=6; sleep_secs=10
	while [ $cnt -gt 0 ] ; do
		get_vold_pid
		if [ -z "$PID" ] ; then
			# it stopped
			exit 0
		fi
		sleep $sleep_secs
		cnt=`expr $cnt - 1`
	done
	echo "Warning: vold did not stop"
fi
 
# all done
exit 0
