#!/bin/sh
/bin/echo "wd=`/bin/pwd`"
# let's not be fascist
umask 022
# indicate that it's a console login
if [ `/usr/bin/tty` = "/dev/console" ];then
  CONSOLE=t
else
  CONSOLE=f
fi
export CONSOLE
# see if we are going to log in with stealth mode.  This does all sorts of
# weird things.  See other dotfiles...
/bin/echo -n "Stealth mode [n]? "
read foo
if [ `/bin/echo ${foo}x|/bin/sed -e 's/[Yy].*/y/'` = "y" ];then
  STEALTH=t;export STEALTH
fi
# if this login is coming in from an xterm, then try to set $DISPLAY properly
if [ ${CONSOLE=f} = "f" ];then
  if [ `/bin/echo ${TERM-xterm}|/bin/sed -e 's/.*:.*/:/'` = ":" ];then
    DISPLAY=$TERM;export DISPLAY
    TERM=xterm;export TERM
    /usr/athena/bin/resize>/tmp/cmd.resize
    . /tmp/cmd.resize
    /bin/rm /tmp/cmd.resize
  else
    if [ ${TERM-.} ];then
      /bin/echo -n "What terminal type are you using [vt100]? "
      read foo
      if [ "${foo-vt100}" ];then
        TERM=$foo;export TERM
        eval `tset -n -s -I -Q`
      fi
    fi
  fi
  # run resize so the tty driver behaves wrt the xterm...
else
  # if this is a local login, then see if it's going to be an
  # X session.
  /bin/echo -n "Start X [n]? "
  read foo
  if [ `/bin/echo ${foo}x|/bin/sed -e 's/[Yy].*/y/'` = "y" ];then
    XSESSION=$$;export XSESSION
    if [ `/bin/athena/machtype` = "rt" ];then
      # get splefty wraparound mouse pointer
      xinit -- /etc/Xibm -wrap
    else
      xinit -- /etc/X
    fi
    # ok... done with X session, now die with the logout
    exec $HOME/config/athena/logout
  fi
fi
# attach the filesystems
. $HOME/config/athena/tktfrob
. $HOME/config/athena/attach
. $HOME/config/athena/environment
/bin/echo ""
# update .project and .logfile to show the login (if not in
# stealth mode...)
if [ ${STEALTH=f} = f ];then
  /bin/echo "*** LOGGED IN:" `date` on `hostname` "***">$HOME/.project
  cat $HOME/.project>>$HOME/logs/usage
  cat $HOME/.project
  $HOME/bin/zlogin
fi
/bin/sh
exec $HOME/config/athena/logout
