#! /bin/sh
# $Id: win_probe.sh,v 1.2 2001/11/07 18:07:02 rlawrence Exp $ 
# SCCSID(@(#)win_probe.sh	1.4) Modified 14:53:23 7/23/01
# Check to see if possible to start up a Windows session by
# doing a test execution of dosexec.
# Options:
#	-l	Basic license check.
#	-e	Check for expired license (does same as "-l")
#	-s	License session limits will allow one more Windows session?
#	-x	Allowed to run a Windows right now using the specifed config?
# The -l, -e and -s options only make sense on Linux systems.
# Return 0 for all ok.

OPT=-x
if [ "x$1" = "x" ]
then
	OPT="x"
else
	OPT="$1"
fi
if [ "x$2" = "x" ]
then
	CONFIG="+kwin"
else
	CONFIG="+k$2"
fi
. /etc/mrgssv.sh
if [ "_$OPT" = "_-l" -o "_$OPT" = "_-e" ]
then
	# License check only.
	# This is only a valid thing to do on the Linux version.
	$STATICMERGE/publicbin/dosexec ++VL  $CONFIG 2> /dev/null
	ERR_CODE=$?
else
	# Full check.  (On Linux versions this includes a license check.)
	$STATICMERGE/publicbin/dosexec ++VLW $CONFIG 2> /dev/null
	ERR_CODE=$?
fi
if  [ $ERR_CODE -eq 0 ]
then
	exit 0
fi
case $ERR_CODE in
200)
	# This means that the Merge driver could not be used,
	# Either because the driver is not installed/loaded,
	# or the maximum simultaneous opens allowed was exceeded.
	# (Linux versions have loadable drivers and a limit
	# on the number of simultaneous opens.)
	if [ "_$OPT" = _"-x" ]
	then
		echo "$MERGENAME driver not loaded or driver limit exeeced."
		exit 21
	fi
	;;
201)
	# Don't expect this because it means that $VARMERGE was invalid.
	# Code 11 is also the code used for this problem by chk_lic_file.sh
	exit 11
	;;
202)
	# Don't expect this either because it means dosexec
	# was not able to allocate memory.
	echo "General failure, out of memory."
	exit 22
	;;
203)
	# Linux version only.
	# This means that dosexec was unable to find the license file
	echo "Some problem using license file"
	# Code 12 is also the code used for this problem by chk_lic_file.sh
	exit 12
	;;
204)
	# Linux version only.
	# This means that the license has invalid stuff
	# in it, but we don't know exactly what the problem is.
	echo "License file has invalid information."
	exit 15
	;;
205)
	# Linux version only.
	echo "License has expired."
	exit 16
	;;
206)
	# Linux version only.
	if [ "_$OPT" = "_-s" -o "_$OPT" = "_-x" ]
	then
		echo "Not allowed to run a Windows session now"
		echo "because the session limit would be exceeded."
		exit 17
	fi
	;;
207)
	if [ "_$OPT" = "_-x" ]
	then
		echo "Not allowed to run a Windows session now because"
		echo "another is currently running from the same location."
		exit 18
	fi
	;;
208)
	if [ "_$OPT" = "_-x" ]
	then
		echo "Cannot start a Windows session now because cannot"
		echo "determine if another Windows session is currently"
		echo "running from the same location."
		echo "(There was a problem with locking the lock file,"
		echo ".merge_win_lock)"
		echo "Is the C drive located on a remote filesystem?"
		echo "If so, the required locking can be problematical."
		exit 19
	fi
	;;
209)
	if [ "_$OPT" = "_-x" ]
	then
		echo "Cannot start a Windows session now because cannot"
		echo "determine if another Windows session is currently"
		echo "running from the same location."
		echo "(There was an unexpected problem with testing the"
		echo "lock file, .merge_win_lock)"
		exit 20
	fi
	;;
210)
	# Linux version only.
	echo "invalid bump license."
	exit 23
	;;
211)
	# Linux version only.
	echo "duplicate bump license."
	exit 24
	;;
*)
	# Any other error code probably does not tell us about the state
	# of the license, but we have to print out something reasonable.
	echo "Unexpected error code returned from dosexec: $ERR_CODE"
	exit 22
	;;
esac

exit 0
