home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #
- # /etc/X11/Xsession
- #
- # global Xsession file -- used by both xdm and xinit (startx)
-
- # If /etc/environment is present, source it. It's useful to put default
- # environment settings in this file, and then source it both here and in
- # /etc/profile.
- if [ -f /etc/environment ]; then
- . /etc/environment
- fi
-
- optionfile=/etc/X11/Xsession.options
-
- sysmodmap=/etc/X11/Xmodmap
- usrmodmap=$HOME/.Xmodmap
- sysresources=/etc/X11/Xresources
- usrresources=$HOME/.Xresources
-
- startup=$HOME/.xsession
-
- startssh=
- sshagent=/usr/bin/ssh-agent
-
- if grep -qs ^use-ssh-agent $optionfile; then
- if [ -x $sshagent -a -z "$SSH_AUTH_SOCK" ]; then
- startssh=yes
- fi
- fi
-
- for errfile in "$HOME/.xsession-errors" "${TMPDIR:-/tmp}/xses-$USER" "/tmp/xses-$USER"; do
- if ( cp /dev/null "$errfile" 2> /dev/null ); then
- chmod 600 "$errfile"
- exec > "$errfile" 2>&1
- break
- fi
- done
-
- case $# in
- 0)
- ;;
- 1)
- case "$1" in
- failsafe)
- if grep -qs ^allow-failsafe $optionfile; then
- if [ -e /usr/bin/X11/xterm ]; then
- if [ -x /usr/bin/X11/xterm ]; then
- exec xterm -geometry +1+1
- else
- # fatal error
- exec > /dev/tty
- echo "Xsession: unable to launch failsafe X session: xterm not executable."
- exit 1
- fi
- else
- # fatal error
- exec > /dev/tty
- echo "Xsession: unable to launch failsafe X session: xterm not found."
- exit 1
- fi
- fi
- ;;
- default)
- ;;
- *)
- program=$(which $1)
- if [ -e $program ]; then
- if [ -x $program ]; then
- startup=$program
- else
- echo "Xsession: unable to launch $1 X session: $1 not executable."
- echo "Xsession: Falling back to default session."
- fi
- else
- echo "Xsession: unable to launch $1 X session: $1 not found."
- echo "Xsession: Falling back to default session."
- fi
- ;;
- esac
- ;;
- *)
- echo "Xsession: unsupported number of arguments ($#)."
- echo "Xsession: Falling back to default session."
- ;;
- esac
-
- if [ -d $sysresources ]; then
- if [ "$(echo $sysresources/*)" != "$sysresources/*" ]; then
- for resourcefile in $(ls $sysresources/* 2> /dev/null | egrep '^[-/_[:alnum:]]*$'); do
- xrdb -merge $resourcefile
- done
- fi
- fi
-
- if [ -x /usr/bin/X11/xmodmap ]; then
- if [ -f $sysmodmap ]; then
- xmodmap $sysmodmap
- fi
- fi
-
- if grep -qs ^allow-user-resources $optionfile; then
- if [ -f $usrresources ]; then
- xrdb -merge $usrresources
- fi
- fi
-
- if [ -x /usr/bin/X11/xmodmap ]; then
- if grep -qs ^allow-user-modmap $optionfile; then
- if [ -f $usrmodmap ]; then
- xmodmap $usrmodmap
- fi
- fi
- fi
-
- if [ -e $startup ] && grep -qs ^allow-user-xsession $optionfile; then
- if [ -x $startup ]; then
- realstartup=$startup
- else
- realstartup="sh $startup"
- fi
- elif [ -e /etc/X11/window-managers ]; then
- for i in `sed 's/#.*//' /etc/X11/window-managers`; do
- if [ -x $i ]; then
- realstartup=$i
- break
- fi
- done
- elif [ -x /usr/bin/x-window-manager ]; then
- realstartup=x-window-manager
- fi
-
- if [ -z "$realstartup" ]; then
- if [ -x /usr/bin/x-terminal-emulator ]; then
- realstartup=x-terminal-emulator
- else
- # fatal error
- exec > /dev/tty
- echo -n "Xsession: unable to start X session: "
- if grep -qs ^allow-user-xsession $optionfile; then
- echo -n "no $startup found, "
- fi
- echo "no window managers, and no terminal emulators found."
- exit 1
- fi
- fi
-
- if [ "$startssh" ]; then
- exec $sshagent $realstartup
- else
- exec $realstartup
- fi
-