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

# /config/xdm/Xsession.t4 -> t4:/tools/Xncd-5.1.140/xdm/Xsession.t4
# That path may not be right.  TODO reconcile with Distfile.
# Hopefully this lash-up won't last long!
#
# 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.
#

PATH=/usr/local/X11/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:/etc:/usr/local/hosts:/usr/local/gnu/bin
# Below worked okay on solaris xdm host.
#PATH=/usr/openwin/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

case $# in
1)
	case $1 in
	failsafe)
		exec xterm -geometry 80x24-0-0
		;;
	esac
esac

startup=$HOME/.xsession

if [ -f $startup ]; then
	exec $startup
fi

# User doesn't have their own script, use this system default code.
# This hacked-down and modified code from /usr/local/X11/.xsession
# is included here, instead of exec'ing that script as is done on xt
.
SYSDIR=/usr/local/X11
SYSLIB=$SYSDIR/lib
WMBINARY=/tools/motif/usr/bin/X11/mwm
# Note that the path above is somewhat fragile, but using it
# saves us a loop checking each dir in PATH for a hit.  Using
# it also helps when we have to invoke it with the xrsh script.

### set default screen saver, set bell on, set bell softly
xset s default b on b 2

### General X resources
# Use system defaults if user doesn't have their own.
if [ -r $HOME/.Xdefaults.Common ]
then
	COMMON=$HOME/.Xdefaults.Common
else
	#COMMON=$SYSDIR/.Xdefaults.Common
	# OK for math.
	COMMON=/usr/local/X11/.Xdefaults.Common
fi
xrdb -load $COMMON

resources=$HOME/.Xresources
if [ -f $resources ]; then
	xrdb -merge $resources
fi

### Mwm resources
# Use system defaults if user doesn't have their own.
if [ -r $HOME/.Xdefaults.Mwm ]
then
	MWM=$HOME/.Xdefaults.Mwm  
else
	#MWM=$SYSDIR/.Xdefaults.Mwm
	# OK for math.
	MWM=/usr/local/X11/.Xdefaults.Mwm
fi
xrdb -merge $MWM

if [ -r $HOME/.mwmrc ]
then
	CONFIGFILE=$HOME/.mwmrc
else
	#CONFIGFILE=$SYSDIR/.mwmrc
	# OK for math.
	CONFIGFILE=/usr/local/X11/.mwmrc
fi

xrsh math \
    xterm -ls -title math -n math -geometry 80x24+110+0 &
# Below works but doesn't propagate DISPLAY setting.
#xterm -geometry 80x24+110+0 -ls -n math -T math -e rlogin math &
xbiff &
# mwm runs on sos4, only
exec /tools/motif/usr/bin/X11/mwm -xrm "mwm*configFile: $CONFIGFILE"
