#!/sbin/sh
#@(#)$Revision: 1.4 $ $Date: 92/10/01 13:36:42 $
#
# Xsession
#
# This is the program that is run as the client for the display manager.
#
# If a .xsession script file exists in the users home directory it is
# run, otherwise the /usr/lib/X11/xdm/sys.xsession default script is used.
#


### Special processing for users with restricted login shell
##  Uncomment script code below to enable restricted login
##
### For xdm a line similar to below should be entered into xdm-config
## DisplayManager*userPath: /bin:/usr/bin:/usr/bin/X11:/usr/openwin/bin:/usr/ucb
##
### For vuelogin a line similar to below should be entered into Xconfig
## Vuelogin*userPath: /bin:/usr/bin:/usr/bin/X11
##
## Both xdm and vuelogin must be restarted in order to re-read config file, eg
## kill -1 pid_of_xdm_or_vuelogin_main_process
###
#
# basename $SHELL | grep -s '^r' 
# if [ $? -eq 0 ]
# then
#   WM=mwm
#   which $WM | awk '$1 == "no"' | grep -s no
#   if [ $? -eq 0 ]
#   then
#     WM=olwm
#   fi
#
#   $WM&
#   sleep 2
#   xterm -ls -geometry 80x24+270+270 -T Restricted_Shell
#   exit 0
# fi
#
####################################################################

### Determine system type and for SunOS 
### set important environment variables

if [ -f /bin/sun ]
then
  OS=sunx
  if [ "x$OPENWINHOME" = "x" ]
  then
     OPENWINHOME=/usr/openwin
     export OPENWINHOME
  fi

  if [ "x$LD_LIBRARY_PATH" = "x" ]
  then
     LD_LIBRARY_PATH=$OPENWINHOME/lib:/usr/lib
     export LD_LIBRARY_PATH
  fi

  PATH=$OPENWINHOME/bin:$OPENWINHOME/demo:$OPENWINHOME/bin/xview:/usr/bin/X11/700X:$PATH
  export PATH

  MANPATH=/usr/man:$OPENWINHOME/man
  export MANPATH

  HELPPATH=$OPENWINHOME/lib/locale:$OPENWINHOME/lib/help
  export HELPPATH

  XFILESEARCHPATH=$OPENWINHOME/lib/%T/%N%S
  export XFILESEARCHPATH

  NOSUNVIEW=1
  export NOSUNVIEW



  ##  
  ##  Determine if we should use xsession or xinitrc
  ##  
  ##  WANTXINITRC is poked from admin scripts and may be set to
  ##  "true" or "false". "true" is default

  WANTXINITRC=true

  SYSXSESSIONFILE=/usr/lib/X11/xdm/sys.xsession
  XSESSIONFILE=".xsession"
  if [ $WANTXINITRC = "true" ]
  then
    if [ -f $OPENWINHOME/lib/Xinitrc ]
    then
      SYSXSESSIONFILE=$OPENWINHOME/lib/Xinitrc
    fi

    if [ -f $HOME/.xinitrc ]
    then
      XSESSIONFILE=".xinitrc"
    fi
  fi

else
  OS=`uname -s`
  XSESSIONFILE=".xsession"
  SYSXSESSIONFILE=/usr/lib/X11/xdm/sys.xsession
fi

export OS



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


###
### do the real work
###

startup=$SYSXSESSIONFILE
resources=$HOME/.Xresources


if [ -f $HOME/$XSESSIONFILE ]; then
	startup=$HOME/$XSESSIONFILE
fi

if [ -f $startup ]; then
	if [ -x $startup -a "$OS" != "sunx" ]; then
		exec $startup
	else
		exec /sbin/sh $startup
	fi
else
	if [ -f $resources ]; then
		xrdb -load $resources
	fi
	twm &
	exec xterm -geometry 80x24+10+10 -ls
fi
