#! /bin/csh -f

switch (`uname`)
	case SunOS:
		set PS_OPTS = -acg 
		if (-d sun4) cd sun4
		breaksw
	case AIX:
		set PS_OPTS = -dea 
		if (-d rs6000) cd rs6000
		breaksw
	case "HP-UX":
		set PS_OPTS = -dea 
		if (-d hp700) cd hp700
		breaksw
endsw

if (-e ../license.dat) then
	set LICENSE_FILE = ../license.dat
else
	set LICENSE_FILE = license.dat
endif
if (-e $LICENSE_FILE) then

	set LOGFILE = ../reportlog
	grep 'FEATURE.*modeltech.* DEMO *$' $LICENSE_FILE > /dev/null
	if ($status == 0) then
		echo "No server is needed for this license file."
		exit(0)
	endif

	grep 'SERVER.*hostname' $LICENSE_FILE > /dev/null
	if ($status == 0) then
		echo "Edit this line in the file ${LICENSE_FILE}:"
		echo ""
		echo -n "   "
		grep 'SERVER.*hostname' $LICENSE_FILE
		echo ""
		echo "Replace 'hostname' with the actual hostname of the server"
		echo "Then run this script again."
		exit(1)
	endif

	ps $PS_OPTS | grep ' modeltech$' > /dev/null
	if ($status == 0) then
		echo "The modeltech license daemon is already running."
		lmstat -c $LICENSE_FILE -i
		exit(1)
	endif

	if (-e /usr/tmp/lockmodeltech) then
		echo "Please delete the lock file at /usr/tmp/lockmodeltech."
		echo "Then run this script again."
		exit(1)
	endif

	if (-e $LOGFILE) mv -f $LOGFILE $LOGFILE.bak
	./lmgrd -c $LICENSE_FILE > $LOGFILE &
	if ($status == 0) then
		echo "Waiting for license manager to start"
		tail -f $LOGFILE | awk '{ print $0 } /modeltech/ { printf("Hit Control-C to continue.\n"); exit }'
	endif
else
	echo "ERROR: Cannot find license file: $LICENSE_FILE "
	echo "       Please contact your distributor or Model Technology"
endif
