#!/bin/sh
trap "exec $HOME/config/athena/logout" 1 2 15
# deal with arguments passed... if there is a -s or s option specified, then
# do a stealth login.
case $# in
0)
  ;;
1)
  case $1 in
  -s|s)
    STEALTH=t;export STEALTH
    ;;
  esac
  ;;
esac
if [ ${STEALTH=f} = t ];then
  /bin/echo "beginning stealth login..."
fi
/bin/echo "wd=`/bin/pwd`"
/bin/echo -n "initiate powerup sequence: "
# load the environment
ENV_SET=f;export ENV_SET
# let's not be fascist
# mark the pid of this process with $XSESSION so that it can be killed
# cleanly
if [ ${XSESSION-.} ];then
  XSESSION=$$;export XSESSION
fi
umask 0022
. $HOME/config/athena/tktfrob
/bin/echo "setting RDISPLAY... "
# cannonicalize stuff so we can do splefty rlogin things
HOST=`/bin/hostname`
RDISPLAY=`/usr/athena/bin/hostinfo -h $HOST`:0.0
export RDISPLAY
/bin/echo "$XSESSION:$USER@$RDISPLAY `/bin/date`"
# check the machine type, and set variables accordingly to modify the
# login.
/bin/echo -n "machine type="
type=`/bin/athena/machtype -c`
case $type in
sun4)
  MACHTYPE=SUN
  sleep_time=2
  ;;
POWER*)
  MACHTYPE=RIOS
  sleep_time=2
  ;;
KN02*)
  MACHTYPE=DS5000
  sleep_time=2
  ;;
KN01*)
  MACHTYPE=DS3100
  sleep_time=3
  ;;
RTPC*)
  MACHTYPE=RT
  sleep_time=7
  ;;
CVAXSTAR)
  MACHTYPE=VS3100
  sleep_time=4
  ;;
VAXSTAR)
  MACHTYPE=VS2000
  sleep_time=10
  ;;
MVAX-II)
  MACHTYPE=VS2
  sleep_time=10
  ;;
*)
  MACHTYPE=unknown
  sleep_time=2
  ;;
esac
/bin/echo -n "$type ($MACHTYPE) "
/bin/echo -n "display type="
if /usr/athena/bin/xrdb -symbols|/bin/grep -s DCOLOR;then
  MONITOR="COLOR"
else
  MONITOR="MONO"
fi
/bin/echo $MONITOR
# load resources for X to configure stuff
/bin/echo -n "loading Xresources... "
/usr/athena/bin/xrdb -load -retain lib/X11/Xresources
# start nawm....
/bin/echo "starting nawm... "
(/afs/sipb.mit.edu/project/sipb/@sys/nawm&) 2>/dev/null
# attach lockers
. $HOME/config/athena/attach
if [ $MACHTYPE = "SUN" ];then
  /bin/athena/detach -h -f x11>/dev/null 2>&1
  /bin/athena/attach -n -h x11r5 emacsdev>/dev/null 2>&1
fi
# configure the console window
/bin/echo "configuring console..."
if [ ${CONSOLE=f} = f ];then
  /usr/athena/bin/config_console
fi
if [ $MONITOR = COLOR ];then
  /usr/athena/bin/xsetroot -fg blue -bg DeepSkyBlue -cursor_name X_Cursor
fi
case $MACHTYPE in
SUN)
  # fix font lossage on sun....
  /usr/athena/bin/xset fp+ /usr/athena/lib/X11/fonts/misc,/usr/athena/lib/X11/fonts/75dpi,/usr/athena/lib/X11/fonts/100dpi
  /usr/athena/bin/xset fp rehash
  /usr/athena/bin/xset c 0
  /usr/athena/bin/xmodmap lib/xmodmap.sun
  ;;
RIOS)
  # tame the rios's fast mouse
  /usr/athena/bin/xset m 3 1
  ;;
RT)
  /usr/athena/bin/xset b 25 2560 30 c 80
  ;;
VS2)
  # deal with insanely slow VS2 mouse
  /usr/athena/bin/xset m 10 1 c 80
  ;;
*)
  /usr/athena/bin/xset b 50 m 5 1 c 80
  ;;
esac
# start xload
/bin/echo -n "activating status display... "
(/usr/athena/bin/xload&) 2>/dev/null
# load background and screensaver
/bin/echo "activating viewscreen... "
/usr/ucb/zcat $HOME/lib/X11/bitmaps/stars.dmp.Z|$HOME/bin/xroot>/dev/null 2>&1
. $HOME/config/athena/environment
# fire up emacs
/bin/echo "activating interfaces... "
case $MACHTYPE in
SUN)
  (/mit/emacs/sun4bin/emacs&) 2>/dev/null
  ;;
*)
  (/usr/athena/bin/emacs&) 2>/dev/null
  ;;
esac
sleep $sleep_time
if [ ${CONSOLE=f} = f ];then
  (/usr/athena/bin/xterm&) 2>/dev/null
fi
/bin/echo -n "activating subspace net... "
# start zwgc, then get motd
/bin/cp $HOME/lib/zephyr/vars $HOME/.zephyr.vars
/usr/athena/bin/zwgc
(/usr/athena/bin/get_message -l|/usr/athena/bin/zwrite -n -q -s 'MOTD' -c notice $USER&) 2>/dev/null
# announce myself... or not, depending on whether or not
# I'm in stealth mode
if [ ${STEALTH=f} = t ];then
  /usr/athena/bin/zctl set exposure opstaff
else
  /usr/athena/bin/zctl set exposure net-announced
fi
# yes, I have to do this to make sure I don't spend too much time
# on-line
(nice -10 /usr/athena/bin/zleave +0300)>/dev/null 2>&1
# check for mail with from, then zwrite it to self
/bin/echo "checking mail... "
/usr/athena/bin/from -t
/bin/echo "checking subspace net... "
# see who's on with znol, and zwrite it to self
# also serves to sub to the login messages...
(/usr/athena/bin/znol -q;zz) 2>/dev/null
# broadcast the login message and update .plan and .logfile
if [ ${STEALTH=f} = f ];then
  $HOME/bin/zlogin
  /bin/echo "*** LOGGED IN:" `date` on `hostname` "***">$HOME/.project
  /bin/cat $HOME/.project>>$HOME/logs/usage
fi
/bin/cat $HOME/.project
sleep 5;
/bin/echo "    --*> W E L C O M E  T O  T H E   D R A G O N ' S  L A I R <*--"
# hang the session on session_gate
if [ ${CONSOLE=f} = f ];then
  hide_console
  exec session_gate -logout
fi
exec $SHELL
