#!/bin/sh

# Default values for session and term
[ "$1" ] || set -- cinnamon

TERM=urxvt

# Source the Standard Stuff from this machine
. /etc/X11/xinit/xinitrc-common
if [ -f $HOME/.Xclients ]; then
    exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients || \
    exec $CK_XINIT_SESSION $SSH_AGENT $HOME/.Xclients
elif [ -f /etc/X11/xinit/Xclients ]; then
    exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients || \
    exec $CK_XINIT_SESSION $SSH_AGENT /etc/X11/xinit/Xclients
else
    # Failsafe settings.  Although we should never get here
    # (we provide fallbacks in Xclients as well) it can't hurt.
    [ -x /usr/bin/xsetroot ] && /usr/bin/xsetroot -solid '#222E45'
    [ -x /usr/bin/xclock ] && /usr/bin/xclock -geometry 100x100-5+5 &
    [ -x /usr/bin/xterm ] && xterm -geometry 80x50-50+150 &
    [ -x /usr/bin/twm ] && /usr/bin/twm
fi

# Source the xprofile files
[ -f /etc/xprofile ] && . /etc/xprofile
[ -f ~/.xprofile ] && . ~/.xprofile

# Set Desktop or Window Manager
case $1 in
	cinnamon)	set -- cinnamon-session;;
	gnome)		set -- gnome-session;;
	kde)		set -- startkde;;
	xfce)		set -- xfce4-session;;
	awesome)	set -- awesome;;
	enlightenment) set -- enlightenment_start;;
esac

# Run the session, if it doesn't work try TERM,
# finally fallback to xterm if there's nothing
exec "$@" || exec "$TERM" || exec xterm