home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 February / PCWorld_2000-02_cd.bin / live / etc / X11 / Xsession < prev    next >
Text File  |  1999-09-19  |  4KB  |  153 lines

  1. #!/bin/sh
  2. #
  3. # /etc/X11/Xsession
  4. #
  5. # global Xsession file -- used by both xdm and xinit (startx)
  6.  
  7. # If /etc/environment is present, source it. It's useful to put default
  8. # environment settings in this file, and then source it both here and in
  9. # /etc/profile.
  10. if [ -f /etc/environment ]; then
  11.   . /etc/environment
  12. fi
  13.  
  14. optionfile=/etc/X11/Xsession.options
  15.  
  16. sysmodmap=/etc/X11/Xmodmap
  17. usrmodmap=$HOME/.Xmodmap
  18. sysresources=/etc/X11/Xresources
  19. usrresources=$HOME/.Xresources
  20.  
  21. startup=$HOME/.xsession
  22.  
  23. startssh=
  24. sshagent=/usr/bin/ssh-agent
  25.  
  26. if grep -qs ^use-ssh-agent $optionfile; then
  27.   if [ -x $sshagent -a -z "$SSH_AUTH_SOCK" ]; then
  28.     startssh=yes
  29.   fi
  30. fi
  31.  
  32. for errfile in "$HOME/.xsession-errors" "${TMPDIR:-/tmp}/xses-$USER" "/tmp/xses-$USER"; do
  33.   if ( cp /dev/null "$errfile" 2> /dev/null ); then
  34.     chmod 600 "$errfile"
  35.     exec > "$errfile" 2>&1
  36.     break
  37.   fi
  38. done
  39.  
  40. case $# in
  41.   0)
  42.     ;;
  43.   1)
  44.     case "$1" in
  45.       failsafe)
  46.         if grep -qs ^allow-failsafe $optionfile; then
  47.           if [ -e /usr/bin/X11/xterm ]; then
  48.             if [ -x /usr/bin/X11/xterm ]; then
  49.               exec xterm -geometry +1+1
  50.             else
  51.               # fatal error
  52.               exec > /dev/tty
  53.               echo "Xsession: unable to launch failsafe X session: xterm not executable."
  54.               exit 1
  55.             fi
  56.           else
  57.             # fatal error
  58.             exec > /dev/tty
  59.             echo "Xsession: unable to launch failsafe X session: xterm not found."
  60.             exit 1
  61.           fi
  62.         fi
  63.         ;;
  64.       default)
  65.         ;;
  66.       *)
  67.         program=$(which $1)
  68.         if [ -e $program ]; then
  69.           if [ -x $program ]; then
  70.             startup=$program
  71.           else
  72.             echo "Xsession: unable to launch $1 X session: $1 not executable."
  73.             echo "Xsession: Falling back to default session."
  74.           fi
  75.         else
  76.           echo "Xsession: unable to launch $1 X session: $1 not found."
  77.           echo "Xsession: Falling back to default session."
  78.         fi
  79.         ;;
  80.     esac
  81.     ;;
  82.   *)
  83.     echo "Xsession: unsupported number of arguments ($#)."
  84.     echo "Xsession: Falling back to default session."
  85.     ;;
  86. esac
  87.  
  88. if [ -d $sysresources ]; then
  89.   if [ "$(echo $sysresources/*)" != "$sysresources/*" ]; then
  90.     for resourcefile in $(ls $sysresources/* 2> /dev/null | egrep '^[-/_[:alnum:]]*$'); do
  91.       xrdb -merge $resourcefile
  92.     done
  93.   fi
  94. fi
  95.  
  96. if [ -x /usr/bin/X11/xmodmap ]; then
  97.   if [ -f $sysmodmap ]; then
  98.     xmodmap $sysmodmap
  99.   fi
  100. fi
  101.  
  102. if grep -qs ^allow-user-resources $optionfile; then
  103.   if [ -f $usrresources ]; then
  104.     xrdb -merge $usrresources
  105.   fi
  106. fi
  107.  
  108. if [ -x /usr/bin/X11/xmodmap ]; then
  109.   if grep -qs ^allow-user-modmap $optionfile; then
  110.     if [ -f $usrmodmap ]; then
  111.       xmodmap $usrmodmap
  112.     fi
  113.   fi
  114. fi
  115.  
  116. if [ -e $startup ] && grep -qs ^allow-user-xsession $optionfile; then
  117.   if [ -x $startup ]; then
  118.     realstartup=$startup
  119.   else
  120.     realstartup="sh $startup"
  121.   fi
  122. elif [ -e /etc/X11/window-managers ]; then
  123.   for i in `sed 's/#.*//' /etc/X11/window-managers`; do
  124.     if [ -x $i ]; then
  125.       realstartup=$i
  126.       break
  127.     fi
  128.   done
  129. elif [ -x /usr/bin/x-window-manager ]; then
  130.   realstartup=x-window-manager
  131. fi
  132.  
  133. if [ -z "$realstartup" ]; then
  134.   if [ -x /usr/bin/x-terminal-emulator ]; then
  135.     realstartup=x-terminal-emulator
  136.   else
  137.     # fatal error
  138.     exec > /dev/tty
  139.     echo -n "Xsession: unable to start X session: "
  140.     if grep -qs ^allow-user-xsession $optionfile; then
  141.       echo -n "no $startup found, "
  142.     fi
  143.     echo "no window managers, and no terminal emulators found."
  144.     exit 1
  145.   fi
  146. fi
  147.  
  148. if [ "$startssh" ]; then
  149.   exec $sshagent $realstartup
  150. else
  151.   exec $realstartup
  152. fi
  153.