#!/bin/sh
# $XConsortium: Xsession /main/10 1995/12/18 18:21:28 gildea $

# 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


case "$1" in
failsafe)
	;;

"")
	;;

*) 	WINDOWMANAGER=$1
 	export WINDOWMANAGER

	test -n "$2" && { LANG=$2; export LANG; }
	;;
esac


 resources1=$HOME/.Xdefaults
 resources2=$HOME/.Xresources
 usermodmap=$HOME/.Xmodmap
    startup=$HOME/.xsession
sysstartup1=/usr/X11R6/lib/X11/xdm/sys.xsession
sysstartup2=/usr/X11R6/lib/X11/xinit/xinitrc

# Default root settings
if [ -f /etc/profile ]; then
	. /etc/profile
fi
xsetroot -def
xsetroot -cursor_name top_left_arrow

# User session
# If the user doesn't have their own xsession, then run
# xinitrc if they exist

if   [ -f $usermodmap ]; then
	xmodmap $usermodmap
fi

if   [ -f $resources1 ]; then
	xrdb -load -retain $resources1
elif [ -f $resources2 ]; then
	xrdb -load -retain $resources2
fi

if   [ -f $startup ]; then
	if   [ -x $startup    ]; then
		exec $startup
	else
		exec /bin/sh $startup
	fi
elif [ -f $sysstartup1 ]; then
	if   [ -x $sysstartup1 ]; then
		exec $sysstartup1
	else
		exec /bin/sh $sysstartup1
	fi
elif [ -f $sysstartup2 ]; then
	if   [ -x $sysstartup2 ]; then
		exec $sysstartup2
	else
		exec /bin/sh $sysstartup2
	fi
else
	xterm -geometry 80x24+10+10 -ls &
	exec fvwm2
fi
