#!/bin/sh
#
# $Id: postinstall.sh,v 1.1 1995/06/21 14:59:06 lduncan Exp $
#
# re-start vold (now that it has been patched)
#
# used for patches that need volmgt to start after files have been patched
# (must be used with preinstall that stops volmgt)
#
# updates:
#   6/95	updated to skip starting 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 re-start volmgt
	exit 0
fi

# ensure vold isn't already running
get_vold_pid
if [ ! -z "${PID}" ] ; then
	echo "Warning: vold already running"
	exit 20		# reboot system
fi

# ensure /dev/volctl is setup us
drvconfig
devlinks
 
# try to start vold
if [ -f /etc/vold.conf -a -f /usr/sbin/vold -a -f /etc/init.d/volmgt ] ; then
	# try to start vold
	/etc/init.d/volmgt start
else
	echo "Warning: can not start vold"
	exit 20		# reboot system
fi
 
# checking to ensure vold started (since system needs reboot if it didn't)
 
sleep 5
get_vold_pid
if [ -z "${PID}" ] ; then
	echo "Warning: vold did not start"
	exit 20
fi
 
# total time to wait is ($cnt * $sleep_amt) seconds
cnt=18; sleep_amt=5	# 90 seconds max
d="/vol/dev"		# hope vold is using /vol
 
# try "cnt" times
while [ $cnt -gt 0 ] ; do
	if [ -d "${d}" ] ; then
		exit 0		# all went ok
	fi
	sleep $sleep_amt
	cnt=`expr $cnt - 1`
done
 
# one last look
if [ ! -d "${d}" ] ; then
	echo "Warning: vold did not seem to start correctly"
	exit 20		# reboot system
fi
 
# all went ok
exit 0
