#! /bin/sh
#
#  /usr/bin/X11/X
#  initialize graphics device and start X Window System
#  $Revision: 1.15 $
#
glGammaFile=/etc/config/system.glGammaVal
glGammaDefault="1.7"

if /etc/chkconfig windowsystem; then
	if [ -x /usr/gfx/gfxinit ]; then
		# need to extract potential -boards argument to give to gfxinit.
		for i in $* ; do
			if [ $next ] ; then brdargs="-boards $i"; break; fi;
			if [ $i = "-boards" ] ; then next=true; fi;
		done
		/usr/gfx/gfxinit $brdargs
		if [ -r $glGammaFile -a -s $glGammaFile ] ; then
			glGamma=`cat $glGammaFile`
		else 
			glGamma=$glGammaDefault
		fi
		/etc/chkconfig debugxserver
		if [ $? = 0 -a -x /usr/bin/X11/Xsgi_d -a -d /usr/lib/X11/dyDDXdebug ] ; then
			exec /usr/bin/X11/Xsgi_d $* -core \
				-ddxdir /usr/lib/X11/dyDDXdebug -gamma $glGamma 
		else
			if [ -x /usr/bin/X11/Xsgi ]; then
				exec /usr/bin/X11/Xsgi $* -gamma $glGamma
			else
				echo "X: /usr/bin/X11/Xsgi not available"
			fi
		fi
	else
		echo "X: /usr/gfx/gfxinit not found"
	fi
else
	echo "X: windowsystem not enabled"
fi
