#!/bin/sh
#
#   Enhanced and documented by Miles O'Neal <meo@rru.com>
#
#   First, redirect output to the user's session error file.

exec > $HOME/.xsession-errors 2>&1

#   Next, see if the user requested a "failsafe" (simple,
#   mostly for debugging) login.  If so, provide only a
#   basic session.  The X Consortium *only* popped up an
#   xterm; I added the window manager.  Make sure everything
#   here is available; use your most popular window manager,
#   or the one your most naive users can deal with, or whatever
#   makes sense in your situation.

case $# in
1)
	case $1 in
	failsafe)
		twm &
		exec xterm -geometry 80x24-0-0
		;;
	esac
esac

#   This isn't a "failsafe" session.  See if the user has a
#   session file.  If so, execute it; otherwise, load their
#   resource file (if any), and provide a basic session as
#   as describe above.

startup=$HOME/.xsession
resources=$HOME/.Xresources

if [ -f $startup ]; then
	exec $startup
else
	if [ -f $resources ]; then
		xrdb -load $resources
	fi
	twm &
	exec xterm -geometry 80x24+10+10 -ls
fi
