#!/bin/sh # Xsession - run as user # Hacked for Mathnet. The original version of this file is in # /etc/X11/xdm/Xsession.orig # Special extra features for Xena's laptop_setup # # Xsession: Setup the xsession and start the xsession # script of the user. # # Copyright (c) 1998-2000 SuSE GmbH Nuernberg, Germany. # please send bugfixes or comments to feedback@suse.de. # # Author: Werner Fink, # # # What we do if we are signaled or do not leave this # script with an appropriate exec call. # : ${failsafe="xterm -ls -T Failsafe -geometry 80x24+0+0"} readonly failsafe trap "exec $failsafe" EXIT SIGHUP SIGINT SIGPIPE SIGTERM SIGIO # # Save our arguments, maybe some of users call # `set' in their profile files. # argv="$@" # # Handle the NoChange option of wdm # /sbin/pidof -s wdm > /dev/null 2>&1 if test $? -eq 0 ; then if test -z "$argv" ; then if test -s $HOME/.wmrc ; then argv=$(<$HOME/.wmrc) #use wm from previous session fi else echo "$argv" > $HOME/.wmrc #save wm fi fi readonly argv # # Disable graphical login if normal login is disabled # login=false while read sh ; do if test "$sh" = "$SHELL" ; then login=true break fi done < /etc/shells if test "$login" != "true" -o "$SHELL" = "/bin/false" ; then trap "exec xmessage -timeout 10 -button okay:1 -center \ \"${0##*/}: Login for $USER is disabled.\"" \ EXIT SIGHUP SIGINT SIGPIPE SIGTERM SIGIO exit 1 fi unset sh login # # Some bash (1 and 2) settings to avoid trouble with # personal profile or bashrc files and failed exec calls. # test -n "$BASH" && set +o posix no_exit_on_failed_exec=1 type shopt &> /dev/null && shopt -s execfail set +e &> /dev/null # # Redirect errors to the standard user log files. # : ${TMPDIR=/tmp} for errfile in "$HOME/.xsession-errors" \ "$TMPDIR/xses-$USER" \ "/tmp/xses-$USER" do # # Avoid bad symbolic links # Provoke a quota violation if the user is over quota. # case "$errfile" in /tmp/*|$TMPDIR/*) rm -f $errfile ;; esac if (echo "Test if user is over quota" > "$errfile") 2> /dev/null ; then chmod 0600 "$errfile" exec > "$errfile" 2>&1 break fi done # # Danger: What will the user do with some of the used variables? # I do not like that ... but even if we source user's files # we want to find our files and use correct variables. # __HOME="$HOME" # Users HOME determined by xdm __DISPLAY="$DISPLAY" # The DISPLAY set by xdm for this session __XAUTHORITY="$XAUTHORITY" # Should be empty in the most cases readonly __HOME __DISPLAY __XAUTHORITY # # Read the default system settings. # test -r /etc/profile && { . /etc/profile > /dev/null 2>&1 ; } # +u reverts -u which causes aborting if using an unset variable. set +u > /dev/null 2>&1 # # Some system defaults # : ${XLIBDIR=/etc/X11} : ${OPENWINHOME=/usr/openwin} readonly XLIBDIR # # the users ~/.profile # test -r ${HOME}/.profile && { . ${HOME}/.profile > /dev/null 2>&1 ; } set +u > /dev/null 2>&1 # # Restore # HOME="$__HOME" DISPLAY="$__DISPLAY" XAUTHORITY="$__XAUTHORITY" TERM=xterm # export OPENWINHOME TERM DISPLAY HOME test -z "$XAUTHORITY" && unset XAUTHORITY || export XAUTHORITY # jimc/CouchNet hack: laptop_setup leaves quite a number of key environment # variables in /dev/shm/laptop_setup.$USER. Source this file if existing. lsfile=/dev/shm/laptop_setup.$USER if [ -r $lsfile ] ; then echo "Setting environment from $lsfile" 1>&2 sed -e 's/=/ /' $lsfile | while read key val junk ; do cmd="echo \$$key" oval="`eval $cmd`" if [ -z "$oval" ] ; then echo "export ${key}='$val'" echo " ${key}='$val' (was unset)" 1>&2 elif [ "$oval" = "$val" ] ; then echo " ${key}='$oval' (unchanged)" 1>&2 else echo " ${key}='$oval' (file wants '$val')" 1>&2 fi done > $lsfile.xdm . $lsfile.xdm #DEBUG rm $lsfile.xdm echo SHEPHERD_PID=$SHEPHERD_PID #DEBUG fi # # Check path (paranoid) # type -p xdm > /dev/null 2>&1 || PATH=$PATH:/usr/X11R6/bin # # Handle arguments given by xdm. # set -- $argv if test $# -ge 1 ; then case "$1" in failsafe) shift exec $failsafe ;; *) # # KDM may overwrites this # WINDOWMANAGER=$1 ; export WINDOWMANAGER if test $# -ge 2 && test -n "$2" ; then LANG=$2 ; export LANG fi shift $# ;; esac fi # The default window manager: # Starting in SuSE 9.3 it's kde. # Starting in SuSE 10.1 it's gnome. # At Mathnet it's still kde. # On CouchNet it's xfce. WMDFLT=fvwm # Handle persistent session type selection. The session type is written # into /var/lib/xdm/dmrc and transcribed to the user's ~/.xdmrc. I'm not # going to parse the whole .dmrc thing. Actually what comes out is the # Name attribute from the desktop file. xdmrcfile=$HOME/.xdmrc if [ -s $xdmrcfile ] ; then xdmrc=`cat $xdmrcfile` ; else xdmrc= ; fi ldmrcfile=/var/lib/xdm/dmrc if [ -s $ldmrcfile ] ; then ldmrc=`cat $ldmrcfile` ; else ldmrc= ; fi # Preference for session selection: # /var/lib/xdm/dmrc > (command line $1> > ~/.xdmrc > ~/.xsession > DFLT session=$WMDFLT for f in $HOME/.xinitrc $HOME/.xsession ; do if [ -x $f ] ; then session=custom ; fi done for f in "$xdmrc" "$ldmrc" "$WINDOWMANAGER" ; do if [ -n "$f" -a "$f" != default ] ; then session=$f fi done # Offer to save a changed session. If the display manager is taking # care of session persistence it will send in the resulting session # name which ends up in WINDOWMANAGER, so in that case bypass this # section. if [ -z "$WINDOWMANAGER" -a "$session" != "$xdmrc" ] && ( [ -z "$xdmrc" ] || \ xmessage -buttons Save:0,NoChange:1 -default NoChange -center \ "Your usual session type is $xdmrc Your coming session will be $session Would you like to save this setting in ~/.xdmrc ? " ) ; then echo $session > $HOME/.xdmrc fi case "$session" in failsafe | Failsafe ) exec $failsafe ;; esac # Translate a session name into the program you're supposed to exec. dtop=`grep -l "Name=$session" /usr/share/xsessions/*.desktop` if [ -n "$dtop" ] ; then WINDOWMANAGER=`sed -n -e 's/^Exec=//p' $dtop` else WINDOWMANAGER=$session fi # # Reset default background and cursor. # xsetroot -def xsetroot -cursor_name top_left_arrow # Supplement the path. for f in /opt/kde3/bin/artswrapper ; do if [ ! -x $f ] ; then continue ; fi if type -p ${f##*/} > /dev/null 2>&1 ; then continue ; fi PATH=${PATH}:${f%/*} done # # Some common user and system files, # do not use `: ${xx=yy}' here. # xdefaults=$HOME/.Xdefaults xresources=$HOME/.Xresources xmodmap=$HOME/.Xmodmap session=$HOME/.xsession xinitrc=$HOME/.xinitrc openwin=$OPENWINHOME/bin/openwin errinit=$XLIBDIR/xinit/xinitrc errsess=$XLIBDIR/xdm/sys.xsession # # Handle the users Xmodmap and Xresources # test -r "$xmodmap" && xmodmap "$xmodmap" if test -r "$xdefaults" ; then xrdb -I$HOME -load -retain "$xdefaults" test -r "$xresources" && xrdb -I$HOME -merge "$xresources" elif test -r "$xresources" ; then xrdb -I$HOME -load -retain "$xresources" fi # User session readonly XSESSION_IS_UP=yes export XSESSION_IS_UP # Kludge to deal with KDE horkage. Starting (?) with gdm-2.20.0 it sets # XDG_DATA_DIRS which screws up KDE (and likely others). If the user has an # old KDE System Config Cache, it will be incomplete and must be removed (KDE # kbuildsycoca will rebuild it; all KDE apps can spawn this.) unset XDG_DATA_DIRS kdecache=/var/tmp/kdecache-$USER/ksycoca if [ -w $kdecache ] ; then t=`find $kdecache ! -newer $0 -print` if [ -n "$t" ] ; then rm $kdecache ; fi fi # "custom" session means to use the user's or system's .xsession file. case X$WINDOWMANAGER in XCustom | Xcustom | X ) export WINDOWBIN=`type -p $WMDFLT` for xses in $session $xinitrc $errsess $errinit $openwin ; do if [ -x $xses ] ; then exec $xses $* fi done # None of those worked. echo "Failed to exec any of $session $xinitrc $errsess $errinit $openwin" 1>&2 exec $failsafe ;; esac # Session type other than default: exec the start program for that desktop # environment. for sess in $WINDOWMANAGER `echo "$WINDOWMANAGER" | tr A-Z a-z` ; do for variant in $sess start$sess $sess-session ; do fpn=`type -p $variant` if [ -n "$fpn" -a -x /$fpn ] ; then exec $XLIBDIR/xdm/wm.xsession $fpn "$@" break 2 fi done done echo "Failed to exec the '$WINDOWMANAGER' window manager" 1>&2 exec $failsafe # If all else fails, signal a screwup; maybe the caller can do something useful. exit 8