#
# postrequest
#
#
# $XiGId: postrequest,v 1.4 1999/05/06 16:41:28 jon Exp $
#
#########################################################################

## arg 1 is the REQUEST_DATA file

#if [ "$INSTALL_ROOT" = "/" ]
#then # we can only do this if root is really root

	if [ "$INSTALL_ROOT" != "/" ]
	then
	        DISPLAY=127.0.0.1:0.0   # a universally accessible display
		export DISPLAY
	fi

	RDATA="$1"

	RCATSET=1	# the message set number we're using for this script
	RCATFILE="ACCELX.cat"	# catalog file for this package

	if [ -r "$RDATA" ]
	then
		set -a
		. $RDATA
		set +a
	fi

	MCATFILE="$(FindCatalog $PKGLOCDIR $RCATFILE)"

	XSETUP="/usr/X11R6/bin/Xsetup"

	if chroot $INSTALL_ROOT [ ! -x $XSETUP ]
	then
		Log "### $0: Cannot find $INSTALL_ROOT/$XSETUP"
		exit 1
	fi

	# X probing...

	if [ "$INSTALL_STARTEDX" -ne 0 ]
	then	# we think we started an Xserver - tell Xsetup about it
		#  so it can probe the hardware.
		probearg="-probe"
	else
		probearg=""
	fi

	if [ "$INSTALL_UI" != "X" ]
	then	# make sure -text is passed
		textopt="-text"
	else
		textopt=""
	fi


	# get basic info from user, including licensing info
	Log "### $0: getting base configuration and lic info"
	if [ "$INSTALL_ROOT" = "/" ]
	then
		Log "### $0 Running: $XSETUP $probearg $textopt -install"
		$XSETUP $probearg $textopt -install
		rv=$?
	else    # not in /
		Log "### $0 Running: $CHROOT $INSTALL_ROOT $XSETUP $probearg $textopt -install"
		# override these for chroot'd run
		export XACCELHOME="/usr/X11R6/lib/X11/AcceleratedX"
		export XKEYSYMDB="$XACCELHOME/etc/XKeysymDB"

		$CHROOT $INSTALL_ROOT $XSETUP $probearg $textopt -install
		rv=$?
	fi

	Log "$0: Xsetup rv = $rv"

	if [ $rv -ne 0 ]
	then	# bad/missing license info, or other error
		xstitle="$(MessageFileCatSet $MCATFILE $RCATSET 3 'Product Licensing FAILED')"
		xsmsg="$(MessageFileCatSet $MCATFILE $RCATSET 4 '\n\nLicensing information was not successfully obtained and saved by Xsetup.\nYou will need to run %s manually as \nroot before the Accelerated-X server will function.' $XSETUP)"

		MessageBox "$xstitle" "$xsmsg"

		# since installation succeeded, even though Xsetup 
		#  did not run correctly, we'll return a successful value.
		exit 0
	fi
#fi # running in /


## JET #####  When/if this is re-activated, remember to modify 
##  MessageCat -> MessageFileCatSet
#else	# success, allow user to setup the xserver
#
#	xstitle="$(MessageCatSet $RCATSET 1 'NOTE')"
#	xsmsg="$(MessageCatSet $RCATSET 2 '\n\nNOTE: By default, the Accelerated-X Server is configured for 640x480 VGA\nresolution.  Do you wish to invoke the Xsetup Utility to configure the \nX server at this time?\n\n')"
#
#	if YesNoBox "$xstitle" "$xsmsg"
#	then    # Shields up! Red Alert!
#		Log "### $0: running $XSETUP"
#		$XSETUP
#		rv=$?
#		if [ $rv -ne 0 -a $rv -ne 1 ]
#		then	# 0 = ok, 1 = didn't save xaccel.ini - still ok...
#			Log "ERROR: Xsetup exited with status $rv"
#
#			# let the user know...
#
#			xstitle="$(MessageCatSet $RCATSET 5 '%s FAILED' $XSETUP)"
#			xsmsg="$(MessageCatSet $RCATSET 6 '\n\nXsetup failed to run successfully.  Please run \n%s manually as root to configure your X Server.  \n\nIf you continue to have problems running Xsetup, \ncontact Xi Graphics technical support.' $XSETUP)"
#
#			MessageBox "$xstitle" "$xsmsg"
#
#			# since the problem is Xsetup related and not Install related,
#			#  we'll return success...
#			exit 0
#		fi
#	fi
#fi

exit 0

