#!/bin/csh -f
#------------------------------------------------------------------------------
# Custom .xsession file
# /mit/tlyu/.xsession
#
# last hacked 911219 by Black Dragon <tlyu@athena.mit.edu>
#
#                           * * * W A R N I N G * * *
#
# This dotfile may be hazardous to your mental health (and your GPA!).
# Use at your own risk.
#
#------------------------------------------------------------------------------

set initdir=/usr/athena/lib/init

# If nocalls is specified, then grab the Athena defaults...

switch ($#argv)
  case 0:
    breaksw
  case 1:
    switch ($1)
      case nocalls:
      case -nocalls:
        echo "Beginning boring nocalls session..."
        source $initdir/xsession $argv
        breaksw
      case stealth:
        echo "Beginning stealth login..."
        setenv STEALTH
        breaksw
      default:
        set bad_args
    endsw
    breaksw
  default:
     set bad_args
endsw

if ($?bad_args) then
  source $initdir/xsesssion $argv
endif

echo -n "Initiate powerup sequence: "
echo -n "Reactors powering up... "

access_off>&/dev/null
echo "Portals secured."
# protection from lame hackers who have nothing better to do
# than steal tickets...

setenv XSESSION $$
echo "XSESSION="$XSESSION
# set a marker in the environment so we can kill -HUP $XSESSION to log out

echo -n "Checking machine type... "
set machtype = `machtype -c`
switch($machtype)
  case POWER:
    setenv MACHTYPE RIOS
    set sleep_time = 2
    breaksw
  case KN02*:
    setenv MACHTYPE DEC5000
    set sleep_time = 3
    breaksw
  case KN01:
    setenv MACHTYPE DEC3100
    set sleep_time = 3
    breaksw
  case RTPC-*:
    setenv MACHTYPE RT
    set sleep_time = 7
    breaksw
  case CVAXSTAR:
    setenv MACHTYPE VAX3100
    set sleep_time = 4
    breaksw
  case VAXSTAR:
    setenv MACHTYPE VAX2000
    set sleep_time = 10
    breaksw
  case MVAX-II:
    setenv MACHTYPE VAX2
    set sleep_time = 12
    breaksw
  case PS2-*:
    setenv MACHTYPE PS2
    set sleep_time = 6
    breaksw
  case next:
    setenv MACHTYPE NeXT
    set sleep_time = 2
    breaksw
  default:
    setenv MACHTYPE unknown
    set sleep_time = 1
endsw
echo "Machine type is: $machtype ($MACHTYPE)"
# set the MACHTYPE variable in case later shell scripts need it

echo -n "Checking monitor type... "
if ($?DISPLAY) then
  set monitor = `machtype -d`
  switch($monitor)
    case QVSS:
    case PM-MONO:
    case apa16:
    case PMAX-MFB:
      setenv MONITOR monochrome
      breaksw
    case SG:
    case PLX:
    case megapel:
    case colorgda:
    case graygda:
    case plx:
    case PM-COLOR:
    case PMAG-BA:
      setenv MONITOR color
      breaksw
    default:
      setenv MONITOR unknown
  endsw
endif
echo "Monitor type is: $monitor ($MONITOR)"
# set the MONITOR variable in case some later shell script needs it

echo -n "Running .cshrc... "
source .cshrc
# load the .cshrc file to set up environment, etc.

echo -n "Loading .Xresources... "
xrdb -load -retain .Xresources
sleep 1
# load the .Xresources file to config apps

echo "Starting vtwm.gamma... "
(/afs/athena.mit.edu/project/windowmanagers/$bindir/vtwm.gamma&)
sleep 1
sleep $sleep_time
# start vtwm.gamma---an awesome window manager

echo "Configuring console..."
(nice +10 xset b 25 2560 30&)
if ($MACHTYPE == RIOS) then 
  (nice +10 xset m 3 1&)
else
  if ($MACHTYPE == VAX2 ) then
    (nice +10 xset m 10 1&)
  else
    (nice +10 xset m 5 1&)
  endif
endif
sleep 1
if (($MACHTYPE == DEC3100)||($MACHTYPE == DEC5000)) then
  (nice +10 xset c 25&)
else
  (nice +10 xset c 0&)
endif
config_console
# configure the console window (it was already up) and the X defaults

echo -n "Activating subspace net... "
rm .zephyr.vars
if ($?STEALTH) then
  ln -s zephyr/vars.stealth .zephyr.vars
else
  ln -s zephyr/vars.all .zephyr.vars
endif
# make the appropriate symlinks as we start up for either stealth or normal
# zwgc exposure
(zwgc&&zctl set away off&&get_message -new -zephyr&)
# load zwgc so we can get zephyrs!

echo -n "Checking mail... "
from -v|zwrite -n $user>&/dev/null
# check for mail with from, then zwrite it to self

echo "Attaching lockers..."
if (! -r ~/rune) then
  (nice +20 attach -h rune&)>&/dev/null
endif
if (! -r /mit/marc) then
  attach -n -h -t AFS -m /mit/marc -e /afs/athena.mit.edu/user/m/marc>&/dev/null
endif
attach -f -n -h -t AFS -m /mit/sipb -e /afs/sipb.mit.edu/project/sipb>&/dev/null
if (! -r /mit/gnu) then
  attach -n -h -t AFS -m /mit/gnu -e /afs/athena.mit.edu/project/gnu>&/dev/null
endif
if ((! -r ~/wugif) && ($MONITOR == color)) then
  (nice +20 attach -n -e -m /wuarchive/archive -e wuarchive.wustl.edu:/archive&)>&/dev/null
endif
rehash

echo "Activating viewscreen..."
if ($MACHTYPE != RIOS) then
  # xroot doesn't work on rios
  (nice +15 zcat ~/pictures/stars.dmp.Z|xroot&)
else
  (xsetroot -solid black&)
endif
(xscreensaver&)
sleep $sleep_time
# load background and screensaver

if (($MACHTYPE != VAX2000) && ($MACHTYPE != VAX2)) then
  # don't do this on a slow VAX; takes too long.
  echo -n "Checking subspace net... "
  (nice +17 znol on|zwrite -n $user&)>&! zephyr/.err.znol
endif
if (($MACHTYPE != VAX2000) && ($MACHTYPE != VAX2)) then
  # this is slow on VAX2000&VAX2
  (nice +20 xznol&)
  sleep $sleep_time
  sleep $sleep_time
endif
# see who's on with znol, and zwrite it to self
# also serves to sub to the login messages...

echo "Activating status display..."
(xload&)
sleep $sleep_time

echo -n "Activating interfaces... "
(xterm -geom 80x50+0+0&)
sleep $sleep_time
sleep $sleep_time
if (($MACHTYPE != VAX2000) && ($MACHTYPE != VAX2)) then
  # no second xterm on a slow VAX
  (xterm -geom 80x50-0+0&)
  sleep $sleep_time
  sleep $sleep_time
endif
(emacs&)
sleep $sleep_time
#start two xterm windows, and emacs

(nice +10 zleave +0300&)>&/dev/null
if (! $?STEALTH) then
  (nice +10 cat zephyr/.zlogin|zwrite -n -d -i login&)>/dev/null
  (echo "*** LOGGED IN:" `date` on `hostname` "***")>! .project
  cat .project>>! .../.logfile
endif
# broadcast the login message

echo "All systems powered up and ready."
echo "    --*> W E L C O M E  T O  T H E   D R A G O N ' S  L A I R <*--"
(sleep 5;hide_console&)
exec session_gate -logout
# session_gate will hold the session open until we log out
# with kill -HUP $XSESSION
