#!/bin/sh
# $Header: /afs/athena.mit.edu/astaff/project/layerdev/src/conf/decmips/RCS/rc.athena,v 1.1 94/11/16 12:00:01 brlewis Exp Locker: brlewis $

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

if [ -f /etc/athena/rc.conf ]; then
	. /etc/athena/rc.conf
fi

if [ "$afs" ]; then
	if [ -d /usr/vice/etc/dkload ]; then
		echo -n "starting AFS client..."		>/dev/console
		cd /usr/vice/etc/dkload
		if [ -f libafs.a ]; then
			echo "Loading AFS kernel extension"	>/dev/console
			./dkload -quiet libafs.a	1>/dev/console 2>&1
                	if [ $? != 0 ]; then
                   		echo -n "error loading AFS..."	>/dev/console
                	fi
        	else
                	echo -n "no kernel library object..."	>/dev/console
		fi
		cd /
	fi
	echo -n "afsd..."					>/dev/console
	if [ "${AFSCLIENT}" = "true" ]; then
		AFSCLIENT=4
	fi
	/etc/athena/afsd -nosettime -daemons "${AFSCLIENT}"
	cp -p /afs/athena.mit.edu/service/aklog /bin/athena/aklog
	echo -n "Configuring AFS cells..."			>/dev/console
	/etc/athena/config_afs
	echo "done"						>/dev/console
else
	if [ "${RMAFS}" = "true" ]; then
		rm -rf /usr/vice/cache
		ed /etc/athena/rc.conf << EOF
/RMAFS/s/true/false/
w
q
EOF
	fi
fi

if [ "$basic_services" ]; then
	echo -n "setting time..."				>/dev/console
	/etc/athena/timed &

	echo -n "zhm..."					>/dev/console
	rm -f /etc/athena/zhm.pid
	/etc/athena/zhm &

	echo "Removing old attach mount points..."		>/dev/console
	/bin/athena/detach -O -n -h -a 
	echo "done."						>/dev/console
	/bin/cp /dev/null /usr/tmp/attachtab

	echo -n "snmpd..."					>/dev/console
	/etc/athena/snmpd &
fi

if [ "$basic_services" -a "${RVDCLIENT}" = "true" ]; then
	echo -n "Getting cluster information: "			>/dev/console
	/etc/athena/save_cluster_info
	if [ -f /etc/athena/clusterinfo.bsh ]; then
		. /etc/athena/clusterinfo.bsh
	else
		echo -n "no information available..."		>/dev/console
	fi
	echo "done."						>/dev/console

	echo "Attaching system libraries:"			>/dev/console
	if [ "${USRLIB}" = "" ]; then
		/bin/athena/attach	 -h -n -o hard $SYSLIB	>/dev/console
	else
		/bin/athena/attach	-h -n -o hard $SYSLIB \
					-h -n -o hard $USRLIB	>/dev/console
	fi
	case $? in
		0)  ;;
		*)
		  echo "Can't attach system libraries...continuing" >/dev/console
		  ;;
	esac
	echo "done."						>/dev/console
fi

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

echo ""								>/dev/console
echo -n "Fixing noattach, nocreate, noremote, and nologin..."	>/dev/console
if [ "${NOCREATE}" = "true" ]; then
	echo -n "" >> /etc/nocreate
else
	rm -f /etc/nocreate
fi
if [ "${NOATTACH}" = "true" ]; then
	echo -n "" >> /etc/noattach
else
	rm -f /etc/noattach
fi
if [ "${NOREMOTE}" = "true" ]; then
	echo -n "" >> /etc/noremote
else
	rm -f /etc/noremote
fi
