#!/bin/sh

trap "" 1 15

PATH=/bin:/usr/ucb:/usr/bin; export PATH

umask 22
. /etc/rc.mit.conf

if [ "${USER}" = "" ]; then
	exec 1>/dev/console 2>&1
	quiet=-q
else
	echo Reactivating workstation...
	quiet=
fi

# Default options
dflags="-clean"

# Parse command line arguments (we only accept one for now -detach)
if [ "$1" = "-detach" ]; then dflags=""; fi

# Flush all NFS uid mappings
/bin/athena/fsid $quiet -p -a

# Tell the Zephyr hostmanager to reset state
if [ -f /etc/athena/zhm.pid ] ; then 
	/bin/kill -HUP `/bin/cat /etc/athena/zhm.pid`
fi

# Then clean temporary areas (including temporary home directories)
/bin/mv /tmp/.X11-unix /tmp/../.X11-unix
/bin/rm -rf /tmp/ > /dev/null 2>&1
/bin/mv /tmp/../.X11-unix /tmp/.X11-unix

# punt any processes owned by users not in /etc/passwd
#/etc/athena/cleanup -passwd

# Finally, detach all remote filesystems
/bin/athena/detach -O -h -n $quiet $dflags -a

# Now start activate again
/etc/athena/save_cluster_info

if [ -f /tmp/clusterinfo.bsh ] ; then
	. /tmp/clusterinfo.bsh
else
	if [ "${RSPCLIENT}" = "true" ]; then
		echo "Can't find library servers."
		exit 1
	fi
fi

if [ "${RSPCLIENT}" = "true" ]; then
	/bin/athena/attach	$quiet -h -n -o hard  $SYSLIB
fi


# Perform an update if appropriate
if [ -f /rsp/auto_update ] ; then 
	/rsp/auto_update reactivate
fi

if [ -f /bin/athena/access_off ]; then /bin/athena/access_off; fi

if [ -f /etc/athena/reactivate.local ]; then
	/etc/athena/reactivate.local
fi

exit 0
