#!/bin/sh
#################################################
# This is the "x11start" shell script that is used to start the X11
#window system.
#
# Usage: x11start [<optional args>]
#
# If there is not a .Xdefaults file in the user's home directory then use
# xrdb.
#################################################

export doxrdb
doxrdb=
if [ -n "$HOME" ]
then
  if [ ! \( -s $HOME/.Xdefaults \) ]
    then
        # There is not a .Xdefaults file in the user's home directory.
    if [ -r /usr/lib/X11/sys.Xdefaults ]
      then
      if [ -s /usr/lib/X11/sys.Xdefaults ]
       then
         doxrdb='xrdb -nocpp -load /usr/lib/X11/sys.Xdefaults'
      fi
    fi
  fi
fi

# Set environment variables that are used by X11 clients.
# (Now done in .x11start so user can change them easily)
# fix up PATH in case user forgot (reeeally ugly thing to do).
case $PATH in
  */usr/bin/X11*/usr/bin*);;# good, it's in the right order
  *) # prepend X11 to /usr/bin
    PATH=`echo $PATH |
  sed -e 's@:/usr/bin:@:/usr/bin/X11:/usr/bin:@g' \
	-e 's@^/usr/bin:@/usr/bin/X11:/usr/bin:@g' \
	-e 's@:/usr/bin$@:/usr/bin/X11:/usr/bin@g' \
	-e 's@^/usr/bin$@/usr/bin/X11:/usr/bin@g'`
    ;;
esac

export PATH

# Look for an X11 startup file (.x11start or sys.x11start) to pass as
# a parameter to xinit.
#
startfile=
#want executable default file
if [ -x /usr/lib/X11/sys.x11start ]
  then
  # Use the system default X11 startup file (it may be user modified).
  startfile=/usr/lib/X11/sys.x11start
fi

if [ \( -n "$HOME" \) -a \( -s $HOME/.x11start \) ]
  then
  # There is an X11 startup file in the user's home directory.
  # find out if it is executable
  if [ -x $HOME/.x11start ]
    then # Use it
    startfile=$HOME/.x11start
  else
    echo '.x11start needs to be executable...'
    if [ -n "$startfile" ]
    then
      echo using default: $startfile
    else
      echo Execing xinit with these parameters: $doxrdb $@
    fi
  fi
fi

# If the user supplied input, pass it on. Otherwise don't pass
# on a null string (which "$@" will be if no parameters are passed in)
if [ "$#" -gt 0 ]
  then
  exec /usr/bin/X11/xinit $startfile "$@"
else
  exec /usr/bin/X11/xinit $startfile
fi

# If the exec fails, the shell dies before it gets here.