#! /bin/sh
# Xsession - run as user

# redirect errors to a file in user's home directory if we can
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

DM_PATH=$PATH
PATH=
test -f /etc/profile && . /etc/profile
test -f $HOME/.profile && . $HOME/.profile
IFS_SAVE=$IFS
IFS=:
for i in $DM_PATH; do
    case :$PATH: in
      *:$i:*) ;;
      ::) PATH=$i;;
      *) PATH=$PATH:$i;;
    esac
done
IFS=$IFS_SAVE
export PATH

test -f /etc/xprofile && . /etc/xprofile
test -f $HOME/.xprofile && . $HOME/.xprofile

case $1 in
    "")
	exec xmessage -center -buttons OK:0 -default OK "Sorry, $DESKTOP_SESSION is no valid session."
	;;
    failsafe)
	exec xterm -geometry 80x24-0-0
	;;
    custom)
	exec $HOME/.xsession
	;;
    default)
	exec startkde
	;;
    *)
	eval exec "$1"
	;;
esac
exec xmessage -center -buttons OK:0 -default OK "Sorry, cannot execute $1. Check $DESKTOP_SESSION.desktop."
