#!/bin/sh

# $XConsortium: startx.cpp,v 1.4 91/08/22 11:41:29 rws Exp $
# $XFree86: xc/programs/xinit/startx.cpp,v 3.0 1994/05/22 00:02:28 dawes Exp $
# 
# This is just a sample implementation of a slightly less primitive 
# interface than xinit.  It looks for user .xinitrc and .xserverrc
# files, then system xinitrc and xserverrc files, else lets xinit choose
# its default.  The system xinitrc should probably do things like check
# for .Xresources files and merge them in, startup up a window manager,
# and pop a clock and serveral xterms.
#
# Site administrators are STRONGLY urged to write nicer versions.
# 




#
# check for installed servers
#
INSTALLED_SERVERS=`ls -1 /usr/X11R6/bin/XF86_* /usr/X11R6/bin/XAccel* 		   /usr/X11R6/bin/Xmetr* 2>/dev/null`


if [ -z "$INSTALLED_SERVERS" ]; then

	echo ""
	echo "You did not install any X-Server \(e.g. XF86_SVGA\)!"
	echo "Please install at least one server to start X."
	echo "I'm aborting now."
	exit 1
fi

#
# check for the first link
#

if [ ! -L /usr/X11R6/bin/X ]; then

	echo ""
	echo "There is no link /usr/X11R6/bin/X to /var/X11R6/bin/X!"
	echo "Please link the files as mentioned above or install the X-Server again."
	echo "I'm aborting now."
	exit 1
fi

#
# check for the second link
# 	

if [ ! -L /var/X11R6/bin/X ]; then

	echo ""
	echo "There is no link /var/X11R6/bin/X to /usr/X11R6/bin/XF86_xxxx which is"
	echo "the binary of the installed X-Server."
	echo "Please link the files as mentioned above or install the X-Server and"
	echo "run xf86config again."
	echo "I'm aborting now."
	exit 1
fi

#
# check if the XF86_xxxx file is an executable or an accidentially copied script or similar things
#

if [ ! -x /var/X11R6/bin/X ]; then

	echo ""
	echo "The file XF86_xxxx (binary of X-Server) doesn't seem to be a binary file."
	echo "Please check it or / and install a new X-Server-binary."
	echo "I'm aborting now."
	exit 1
fi



userclientrc=$HOME/.xinitrc
userserverrc=$HOME/.xserverrc
sysclientrc=/usr/X11R6/lib/X11/xinit/xinitrc
sysserverrc=/usr/X11R6/lib/X11/xinit/xserverrc
clientargs=""
serverargs=""






if [ -f $userclientrc ]; then
    clientargs=$userclientrc
else if [ -f $sysclientrc ]; then
    clientargs=$sysclientrc
fi
fi




if [ -f $userserverrc ]; then
    serverargs=$userserverrc
else if [ -f $sysserverrc ]; then
    serverargs=$sysserverrc
fi
fi

whoseargs="client"
while [ "x$1" != "x" ]; do
    case "$1" in
	/''*|\.*)	if [ "$whoseargs" = "client" ]; then
		    clientargs="$1"
		else
		    serverargs="$1"
		fi ;;
	--)	whoseargs="server" ;;
	*)	if [ "$whoseargs" = "client" ]; then
		    clientargs="$clientargs $1"
		else
		    serverargs="$serverargs $1"
		fi ;;
    esac
    shift
done

xinit $clientargs -- $serverargs












