#!/bin/sh
# $Header: /afs/athena.mit.edu/astaff/project/layerdev/src/conf/RCS/reactivate,v 1.2 93/09/23 14:37:54 mar Exp $

PATH=/bin:/bin/athena:/usr/ucb

umask 22
. /etc/athena/rc.conf

# Default options
dflags="-clean"


# Set various flags (based on environment and command-line)
if [ "$1" = "-detach" ]; then dflags=""; fi

if [ "${USER}" = "" ]; then
	# Only run if no one logged in
	if [ `who | wc -l` -ne 0 ]; then
		exit 0
	fi
	exec 1>/dev/console 2>&1
	quiet=-q
else
	echo Reactivating workstation...
	quiet=
fi


/var/athena/layer_athena status subsets > /var/athena/subsets$$
if [ -s /var/athena/subsets$$ ]; then
	. /var/athena/subsets$$
fi
rm -f /var/athena/subsets$$

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

# Cleanup?

# Detach
	detach $quiet -O -h -n -a

# attach syspack
	/etc/athena/save_cluster_info
	. /etc/athena/clusterinfo.bsh
	if [ "${SYSLIB}" ]; then
		attach $quiet -h -n -o hard $SYSLIB
	fi
fi


if [ "$login" ]; then
	if [ -f /etc/passwd.local ] ; then
	    cp -p /etc/passwd.local /etc/ptmp && /bin/mv -f /etc/ptmp /etc/passwd
	    /bin/rm -f /etc/passwd.dir /etc/passwd.pag
	fi
	if [ -f /etc/group.local ] ; then
	    cp -p /etc/group.local /etc/gtmp && /bin/mv -f /etc/gtmp /etc/group
	fi
fi


if [ "$afs" ]; then
	# Reconfigure AFS state
	if [ -f /afs/athena.mit.edu/service/aklog ] ; then
	    cp -p /afs/athena.mit.edu/service/aklog /bin/athena/aklog.new && \
	    /bin/test -s /bin/athena/aklog.new && \
	    /bin/mv /bin/athena/aklog.new /bin/athena/aklog
	    /bin/rm -f /bin/athena/aklog.new
	fi
	/etc/athena/config_afs > /dev/null 2>&1 &
fi

if [ -f /afs/athena.mit.edu/system/layer/`machtype`bin/layer_athena ] ; then
    cp -p /afs/athena.mit.edu/system/layer/`machtype`bin/layer_athena /var/athena/layer_athena.new && \
    /bin/test -s /var/athena/layer_athena.new && \
    /bin/mv /var/athena/layer_athena.new /var/athena/layer_athena
    /bin/rm -f /var/athena/layer_athena.new
fi

# check for update
NEWVERS=`cat /srvd/.rvdinfo | awk '{print $5}'`
VERSION=`cat /var/athena/.rvdinfo | awk '{print $5}'`
if [ -r /srvd/.rvdinfo -a "$NEWVERS" != "$VERSION" ]; then
	echo "Workstation undergoing Athena software update" > /etc/nologin
	echo "Workstation undergoing Athena software update" > /dev/console
	/var/athena/layer_athena autoupdate
	rm -f /etc/nologin
fi

