#!/bin/sh
# $XConsortium: Xsession,v 1.7 92/08/06 11:08:14 gildea Exp $

# /config/xdm/Xsession.v3	installed as v3:/tools/Xncd/xdm/Xsession.v3
#
# NOTICE: Do not edit the copy of this file that is installed!
# Any changes will be lost when it is overwritten by the master copy.
#

# Try this without setting PATH in here.  Do without it if we can!
#PATH=/usr/openwin/bin:/usr/local/X11/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:/etc:/usr/local/hosts:/usr/local/gnu/bin
#export PATH

# Redirect errors to a file in user's home directory if we can.
for errfile in "$HOME/.xsession-errors" "/tmp/xses-$USER"
do
	if ( cp /dev/null "$errfile" 2> /dev/null )
	then
		chmod 600 "$errfile"
		exec > "$errfile" 2>&1
		break
	fi
done

# Check the user's shell, and if it is not a 'good' one, use an xterm
# to display the message embedded in their goofy shell.
case "$SHELL" in
    /users/* ) 
	    # Maybe someday get a bigger font in this xterm, with resources.
	    #xrdb -load $resources
	    exec xterm -geometry 80x24+55+125
    ;;
esac

# There's some funny keypress sequence that causes xdm to pass in "failsafe",
# therefore tripping the failsafe clause.  Never used it, but keep the code.
case $# in
1)
	case $1 in
	failsafe)
		exec xterm -geometry 80x24-0-0
		;;
	esac
esac

# Capture the environment into the error file.  Handy for debugging.
set

# The ncd module only adds to the PATH, but it may do more someday.
. /tools/modules/init/sh
module add ncd

# Start the NCD motif-like window manager, running in the xterm itself.
DISPLAY_HOST=`echo $DISPLAY | sed -e 's/:.*//'`
case "$DISPLAY_HOST" in
    ncd* )
	    rsh $DISPLAY_HOST wm
	    NCD=true
	    ;;
    * )
	    # Start the motif window manager.
	    echo "Would start the Motif window manager (mwm)."
	    NCD=false
	    ;;
esac

# Hardwired for now.  Later can be `host_select`.
#COMPUTE_HOST=hub
if [ -x /tools/Xncd/xdm/host_select ]
then
    # Ditch stderr because host_select whines about the version of libX11.
    # The argument lets eris be the default host.
    COMPUTE_HOST=`/tools/Xncd/xdm/host_select eris` 2>/dev/null
else
    COMPUTE_HOST=eris
fi

# if [ "$NCD" = true ]
# then
    rsh $COMPUTE_HOST /tools/ncd/bin/ncdrunterm		\
		-ls					\
		-display $DISPLAY			\
		-title $COMPUTE_HOST			\
		-xrm NCDterm.iconName:$COMPUTE_HOST	\
		-xrm NCDterm.blinkCursor:true
# fi

# HERE IS THE LAST COMMAND.  When it exits, the session is OVER!
exec xterm -geometry 80x24+10+10 -ls

#/tools/ncd/bin/ncdrunwm


#exec xterm -geometry 80x24+10+10 -ls

#------- boilerplate that may be useful later ------------
## Most of this I'm just short-circuiting for now.  All I want is a test.
##startup=$HOME/.xsession
##resources=$HOME/.Xresources
##
##if [ -f $startup ]; then
##	exec $startup
##else
##    if [ -f /usr/local/X11/.xsession ]; then
##	exec /usr/local/X11/.xsession
##    else
##	if [ -f $resources ]; then
##		xrdb -load $resources
##	fi
##	twm &
##  	exec xterm -geometry 80x24+10+10 -ls
##    fi
##fi
