
HOMEDIR="/usr/xdemo"
cd $HOMEDIR

XSCRIPT=/usr/bin/X11/X11
TITLE=" X Window Demo  "
HI_RES=""
MONO=""
VGA1=""
VGA2=""

if [ ! -f readcfg ]; then
	echo "\n\007$0: WARNING: readcfg not found"
elif [ ! -x readcfg ]; then
	echo "\n\007$0: WARNING:  readcfg not executable"
else
	OPUSCFG=`readcfg | grep "^<X=X11"`
fi

case $OPUSCFG in
	*vga1*)
		VGA1=1
		;;
	*vga2*)
		VGA2=1
		;;
	*age*)
		HI_RES=1
		;;
	*ev235*)
		MONO=1
		;;
	*hercules*)
		echo "\007\nThis demo does not support hercules monitors - sorry."
		exit 1
		;;
	*)
		while :; do
			echo "\n===== X Window Demo =====\n"
			echo "\nEnter the type of monitor:\n"
			echo "0) exit"
			echo "1) monochrome"
			echo "2) vga"
			echo "3) extended vga"
			echo "4) hi-resolution color"
			echo "\nEnter [1-4]: \c"
			read ANS
			case $ANS in
				0)
					exit
					;;
				1)
					MONO=1
					;;
				2)
					VGA1=1
					;;
				3)
					VGA2=1
					;;
				4)
					HI_RES=1
					;;
				*)
					echo "\n\007Invalid response."
					sleep 1
					continue
					;;
			esac
			break
		done
		;;
esac

X_RUNNING=`ps -e | grep xdm | line`
if [ "$X_RUNNING" ]; then
	set $X_RUNNING
	X_RUNNING=$4
fi

if [ ! "$X_RUNNING" ]; then
	if [ ! -f /usr/options/XCORE.name ]; then
		echo "\n\007$0: /usr/options/XCORE.name not found."
		echo "\nThe XCORE and XDEMO packages must be installed in order to run this demo."
		exit 1
	fi
	if [ ! -f /usr/options/XDEMO.name ]; then
		echo "\n\007$0: /usr/options/XDEMO.name not found."
		echo "\nThe XDEMO package must be installed in order to run this demo."
		exit 1
	fi
	if [ ! -f $XSCRIPT ]; then
		echo "\n\007$0: $XSCRIPT not found"
		exit 1
	fi
	echo "\nBringing up X, please login as 'xdemo'...\n"
	sleep 3
	$XSCRIPT
	exit
fi

if [ $HI_RES ]; then
	GEOM="240x350-30-30"
	BGCOLOR="SteelBlue"
	FGCOLOR="White"
	FLAG="hi_res"
elif [ $VGA1 ]; then
	GEOM="230x300-50+750"
	BGCOLOR="blue"
	FGCOLOR="red"
	FLAG="vga1"
elif [ $VGA2 ]; then
	GEOM="230x300-50+750"
	BGCOLOR="blue"
	FGCOLOR="red"
	FLAG="vga2"
elif [ $MONO ]; then
	GEOM="230x300-50+750"
	BGCOLOR="white"
	FGCOLOR="black"
	FLAG="mono"
fi

$HOMEDIR/xdemo_menu -$FLAG -g $GEOM -title "$TITLE" -bg $BGCOLOR -fg $FGCOLOR
