#!/bin/sh # $Xorg: startx.cpp,v 1.3 2000/08/17 19:54:29 cpqbld 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. # # $XFree86: xc/programs/xinit/startx.cpp,v 3.16tsi Exp $ # These files (if they exist) are used to set up the X related environment. We used to # exec .xsession at this location, but that can interfere with choosing a session type # through XDM/KDM/GDM so it was moved to after a requested session is started. Since # that means that .xsession might never be run at all when using XDM/KDM/GDM, support # for the xprofile was added to allow a way for the user to customize the X environment. if [ -r /etc/xprofile ]; then source /etc/xprofile fi if [ -r $HOME/.xprofile ]; then source $HOME/.xprofile fi userclientrc=$HOME/.xinitrc userserverrc=$HOME/.xserverrc sysclientrc=/usr/X11R6/lib/X11/xinit/xinitrc sysserverrc=/usr/X11R6/lib/X11/xinit/xserverrc defaultclient=/usr/X11R6/bin/xterm defaultserver=/usr/X11R6/bin/X defaultclientargs="" defaultserverargs="" clientargs="" #serverargs="-dpi 96 -ac -nolisten tcp" serverargs="-ac -nolisten tcp" echo Create_Date_String Initialize_Status_Message startx # Programmatically assign $DISPLAY to next available session. DISPLAY=0 while [ -e "/tmp/.X${DISPLAY}-lock" ] ; do DISPLAY=$(( $DISPLAY + 1 )) done # Select one of the following schemes. The VT variable will be used to # determine the virtual terminal (vt) number and also and inform the user # of the respective Ctrl-Alt-Fn keyboard shortcut. # Scheme One: # Calculate the vt the same way as X. Determine the number of available tty # consoles and then add 1. Later in the script when launching X from xinit, # the vt assignment will coincide as to what X normally would have assigned anyway. # In other words, no damage done and no confusion to X. But determining the VT # variable at this stage also helps inform the user of the Ctrl-Alt-Fn keyboard # shortcut. # NUMTTY=? # VT=$(($NUMTTY+1)) # Scheme Two: # Unless specifically instructed, X assigns the first vt number in sequence # with the number of tty consoles. If 3 tty consoles are enabled in # /etc/inittab, then X assigns the next vt to vt4. Most people never reduce # the six tty consoles that most distros provide in /etc/inittab. But even # if inittab is modified for fewer than 6 tty consoles, the following routine # ensures the Ctrl-Alt-Fn keyboard shortcut remains consistent as if we still # had the original 6. Therefore we increment the next display number by 7 # to force the vt number. If choosing this option, and using XDM or KDM as # login managers, be sure to also edit the respective Xsession config files to # forcibly assign the vt consistent with this scheme. The tty number could be # used here, but using the DISPLAY variable creates a nice correspondence with # the function keys. That is, regardless of which tty X is launched from, the # function keys remain consistent with the DISPLAY number. Thus, Display 0 will # always be assigned vt7, Display 1 to vt8, Display 2 to vt9, etc. VT=$(($DISPLAY+7)) # Scheme Three: # Similar to the previous two schemes, we calculate the vt number using the ttys, but # instead of incrementing by 1, we increment by 7. This schemed keeps the vt number # consistent with the tty. That is, from tty1 we use vt7, tty2 we use vt8, etc. # NUMTTY=? # VT=$(($NUMTTY+7)) echo -e "Using X session DISPLAY ${BOLDWHITE}:${DISPLAY}${COLOR_RESET}." echo "startx: Using X session DISPLAY :${DISPLAY}." >> $STATUSFILE echo -e "Using virtual terminal ${BOLDWHITE}vt$VT${COLOR_RESET}." echo "startx: Using virtual terminal vt$VT." >> $STATUSFILE echo -e "Use ${BOLDYELLOW}(Ctrl)-Alt-F$VT${COLOR_RESET} to toggle to this virtual terminal." echo "startx: Use (Ctrl)-Alt-F$VT to toggle to this virtual terminal." >> $STATUSFILE if [ -f $userclientrc ]; then defaultclientargs=$userclientrc elif [ -f $sysclientrc ]; then defaultclientargs=$sysclientrc fi if [ -f $userserverrc ]; then defaultserverargs=$userserverrc elif [ -f $sysserverrc ]; then defaultserverargs=$sysserverrc fi whoseargs="client" while [ x"$1" != x ]; do case "$1" in # '' required to prevent cpp from treating "/*" as a C comment. /''*|\./''*) if [ "$whoseargs" = "client" ]; then if [ x"$clientargs" = x ]; then client="$1" else clientargs="$clientargs $1" fi else if [ x"$serverargs" = x ]; then server="$1" else serverargs="$serverargs $1" fi fi ;; --) whoseargs="server" ;; *) if [ "$whoseargs" = "client" ]; then clientargs="$clientargs $1" else # display must be the FIRST server argument if [ x"$serverargs" = x ] && \ expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then display="$1" else serverargs="$serverargs $1" fi fi ;; esac shift done # process client arguments if [ x"$client" = x ]; then # if no client arguments either, use rc file instead if [ x"$clientargs" = x ]; then client="$defaultclientargs" else client=$defaultclient fi fi # process server arguments if [ x"$server" = x ]; then # if no server arguments or display either, use rc file instead if [ x"$serverargs" = x -a x"$DISPLAY" = x ]; then server="$defaultserverargs" else server=$defaultserver fi fi if [ x"$XAUTHORITY" = x ]; then XAUTHORITY=$HOME/.Xauthority export XAUTHORITY fi removelist= # set up default Xauth info for this machine case `uname` in Linux*) if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then hostname=`hostname -f` else hostname=`hostname` fi ;; *) hostname=`hostname` ;; esac #authdisplay=${display:-:0} authdisplay=${display:-:$DISPLAY} mcookie=`mcookie` for displayname in $authdisplay $hostname$authdisplay; do if ! xauth list "$displayname" | grep "$displayname " >/dev/null 2>&1; then xauth -q << EOF add $displayname . $mcookie EOF removelist="$displayname $removelist" fi done # uncomment the following for troubleshooting # echo "display = $DISPLAY" # echo "displayname = $displayname" # echo "client = $client" # echo "clientargs = $clientargs" # echo "server = $server" # echo "serverargs = $serverargs" # echo "xinit $client $clientargs -- $server :$DISPLAY vt$VT $serverargs" # exit 1 echo -e "${BOLDWHITE}Client args:${COLOR_RESET} $client $clientargs" echo "startx: Client args: $client $clientargs" >> $STATUSFILE echo -e "${BOLDWHITE}Server args:${COLOR_RESET} $server :$DISPLAY vt$VT $serverargs" echo "startx: Server args: $server :$DISPLAY vt$VT $serverargs" >> $STATUSFILE # a short pause so viewers can see what is happening sleep 1 xinit $client $clientargs -- $server :$DISPLAY vt$VT $serverargs 2>/dev/null if [ "$?" = "0" ] ; then echo echo "startx: Seems everything went okay with this X session!" >> $STATUSFILE echo -e "${BOLDWHITE}startx: Seems everything went okay with this X session!${COLOR_RESET}" else echo echo "startx: Error! Could not start the X graphical environment!" >> $STATUSFILE echo -e "${BOLDRED}startx: Error! Could not start the X graphical environment!${COLOR_RESET}" fi Text_Break echo if [ x"$removelist" != x ]; then xauth remove $removelist fi if command -v deallocvt > /dev/null 2>&1; then deallocvt fi exit 0