#!/bin/sh
#
# 
# @(#)preinstall	1.9 9/8/93 Copyright (c) 1993 by Sun Microsystems, Inc.
#
# preinstall script for lmgrd
licdir="/etc/opt/licenses"
lmgrdname="lmgrd.ste"
combined_lic="licenses_combined"
rest_of_path="SUNWste/license_tools"
ps -ef | grep ${lmgrdname} | grep -v grep > /dev/null 2>&1
if [ $? -eq 0 ]; then
	echo "Before installing the new license manager software, an attempt will
be made to halt the currently executing license manager daemon.
The license manager daemon will be restarted after the software is installed." 
	if [ ! -f $licdir/$combined_lic ]; then
		echo
		echo "No License File $licdir/$combined_lic - Cannot Kill License Manager Daemon"
	elif [ ! -x ${licdir}/lmdown ]; then
		echo 
		echo "Cannot execute ${licdir}/lmdown - Cannot Kill License Manager Daemon"
	else
		echo 
		echo "Attempting to halt license manager daemon"
#This code sucks, but, unfortunately, the daemon is not necessarily down
#when lmdown completes, so we don't want to start up a new daemon until
#the old one goes down.

		${licdir}/lmdown -c $licdir/$combined_lic -q &
		i=0
		downstatus=1
		ps -ef | grep ${lmgrdname} | grep -v grep > /dev/null 2>&1
		while [ $? -eq 0 ]
		do
			sleep 1
			i=`expr $i + 1`
			if [ $i -gt 30 ]
			then
				downstatus=0
				break
			fi
			ps -ef | grep ${lmgrdname} | grep -v grep > /dev/null 2>&1
		done
		if [ $downstatus -eq 0 ]
		then
			echo "Unable to take down license daemon ${lmgrdname}"
		fi
	fi
fi
exit 0
