#!/bin/sh
# $XConsortium: Xsession,v 1.9 92/08/29 16:24:57 gildea Exp $

# 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

# Since xdm doesn't run a bash -login shell (or any other login shell)
# then read the files that it would, to set up the user's environment
profile=/etc/profile
userprofile=~/.profile

if [ -e $profile ]; then
        source $profile
fi
if [ -e $userprofile ]; then
        source $userprofile
fi

# The path built into XFree86's xdm binary assumes it's running some kind
# of BSD (/usr/ucb, /etc) so this section makes sure all the standard
# Linux binary directories are included:
if [ "`whoami`" = "root" ]; then
 PATH=/usr/local/sbin:/sbin:/usr/sbin:/usr/local/bin:/bin:/usr/bin:$PATH
else
 PATH=/usr/local/bin:/bin:/usr/bin:$PATH
fi

# If the user doesn't have their own xsession, then run openwin or
# xinitrc if they exist
startup=$HOME/.xsession

# Uncomment the following line if you want xdm to start up with whatever
# window manager you get when you run "startx"
sysstartup1=/usr/X11R6/lib/X11/xinit/xinitrc

# Uncomment the following line if you want xdm to start using "openwin" (Must
# comment out the line above)
sysstartup2=$OPENWINHOME/bin/openwin

resources=$HOME/.Xresources

if [ -f "$startup" ]; then
	exec "$startup"
elif [ -x "$sysstartup1" ]; then
        exec $sysstartup1
elif [ -x "$sysstartup2" ]; then
        XDM="running"
        export XDM
        exec $sysstartup2
else
	if [ -f "$resources" ]; then
		xrdb -load "$resources"
	fi
	twm &
	exec xterm -geometry 80x24+10+10 -ls
fi
