#! /bin/sh 
#
#	NAME
#		Xsession
#
#	DESCRIPTION
#		The xdm Xsession script.
#
#	FILES
#		XPstartup
#
#	RCS VERSION
#		$Header: /tmp_mnt/vol/nwd/tools/media/X11/XP/bin/xdmconfig/RCS/Xsession.ibm,v 1.6 1992/07/10 02:42:54 stank Exp $
#
# Compute the TEKXP_ROOT directory from the Xsession or xdm invocation path.  
# Assumes that we are invoking this script as 
# $TEKXP_ROOT/bin/ibmRS6000/xdmconfig/Xsession.
# (The Xsession path comes from xdm-config; if cd-relative, use current
# directory and reset current dir to $HOME.)

if [ "`echo $0 | fgrep /xdmconfig/Xsession`" = "" ]
then
    TEKXP_ROOT=`pwd | sed -e "s;/xdmconfig;;"`
    cd $HOME
else
    TEKXP_ROOT=`echo $0 | sed -e "s;/xdmconfig/Xsession;;"`
fi

# Let user/system scripts know that they are running under xdm.
# Export the TEKXP_ROOT directory so that user session scripts can invoke
# $TEKXP_ROOT/bin utilities.
XDM_INITIATED=TRUE
export XDM_INITIATED TEKXP_ROOT

#
# Check to see if the failsafe option is desired.
# If so, then create the Failsafe xterm instead of the xsession.
# Check for debug mode, pass it along.
#
    case $# in
      1)
	case $1 in
	  failsafe)
	    # This is about as failsafe as I can imagine.
            # If this fails try xterm.
	    exec /usr/bin/X11/aixterm -n "Failsafe Session Control" -geometry 80x24+1+30 -xrm "*iconGeometry:+150+1" -ls
	    ;;
	  -debug)
	   debug=true
	    ;;
	esac
    esac

#
# Set up the term.  Set the SHELL if the SHELL is not set
TERM=aixterm
export TERM
if [ -z "$SHELL" ] ; then
    SHELL="/bin/sh"
    export SHELL
fi

resources=$HOME/.Xresources
for startup in $HOME/.xsession $HOME/.Xsession
do
    if [ -f $startup ]; then
        if [ -x $startup ] ; then
            exec $startup
            exit 0
        else
            exec /bin/sh $startup
            exit 0
        fi
    fi
done

# No Xsession files were found, so execute the default xterm
if [ -f $resources ] ; then
    xrdb -load $resources
fi
exec aixterm -ls
