#!/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 $# in
1)
	case $1 in
	failsafe)
		exec xterm -geometry 80x24-0-0
		;;
	esac
esac

resources1=$HOME/.Xdefaults
resources2=$HOME/.Xresources
usermodmap=$HOME/.Xmodmap
startup1=$HOME/.xsession
startup2=$HOME/.xinitrc
sysstartup1=/usr/X11R6/lib/X11/xinit/xinitrc
sysstartup2=$OPENWINHOME/bin/openwin

# 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 $startup1 ]; then
	if   [ -x $startup1    ]; then
		exec $startup1
	else
		exec /bin/sh $startup1
	fi
elif [ -f $startup2 ]; then
	if   [ -x $startup2 ]; then
		exec $startup2
	else
		exec /bin/sh $startup2
	fi
elif [ -x $sysstartup1 ]; then
	if   [ -x $sysstartup1 ]; then
		exec $sysstartup1
	else
		exec /bin/sh $sysstartup1
	fi
elif [ -x $sysstartup2 ]; then
	if   [ -x $sysstartup2 ]; then
		exec $sysstartup2
	else
		exec /bin/sh $sysstartup2
	fi
else
	xterm -geometry 80x24+10+10 -ls &
	exec fvwm
fi
