#!/bin/sh
# $Header: /afs/athena.mit.edu/astaff/project/layerdev/src/conf/rsaix/RCS/rc.athena,v 1.2 94/07/18 17:53:13 probe Exp Locker: probe $

case $1 in 
'start')
	/var/athena/layer_athena status subsets > /tmp/subsets
	if [ -s /tmp/subsets ]; then
		. /tmp/subsets
	fi

	# Do any post-install steps as necessary
	if [ -f /var/athena/rc.install ]; then
		. /var/athena/rc.install
		rm /var/athena/rc.install
	fi

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

	if [ "$afs" ]; then
		sh /usr/vice/etc/modload/rc.modload.client

		echo  "afsd..."				>/dev/console

		if [ "${AFSCLIENT}" = "true" ]; then AFSCLIENT=4; fi
		AFSOPTS="${AFSOPTS} -daemons ${AFSCLIENT-4}"

		/usr/vice/etc/afsd ${AFSOPTS}
		cp -p /afs/athena.mit.edu/service/aklog /bin/athena/aklog

		echo  "configuring AFS cells..."		>/dev/console
		sh /etc/athena/config_afs
		echo "done"					>/dev/console
	        ln -s /afs/athena/system/sun4m_53/srvd.77 /srvd

	fi

	if [ "$basic_services" ]; then

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

		if [ -f /etc/athena/snmpd ]; then
			echo  "snmpd..."			>/dev/console
			/etc/athena/snmpd &
		fi

		echo "Removing old attach mount points..."	>/dev/console
		/bin/athena/detach -O -n -h -a 
		echo "done."					>/dev/console
	fi

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

		echo "Attaching system libraries:"		>/dev/console
                rm /srvd
		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  "Fixing noattach, nocreate, noremote, and nologin..." >/dev/console
	if [ "${NOCREATE}" = "true" ]; then
		echo  "" >> /etc/nocreate
	else
		rm -f /etc/nocreate
	fi
	if [ "${NOATTACH}" = "true" ]; then
		echo  "" >> /etc/noattach
	else
		rm -f /etc/noattach
	fi
	if [ "${NOREMOTE}" = "true" ]; then
		echo  "" >> /etc/noremote
	else
		rm -f /etc/noremote
	fi
	echo " done!"                                           > /dev/console
	;;
'stop')
	pid=`/usr/bin/ps -e | /usr/bin/grep timed | /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
	if test "$pid"
	then
		kill $pid
	fi
	pid=`/usr/bin/ps -e | /usr/bin/grep snmpd | /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
	if test "$pid"
	then
		kill $pid
	fi
	pid=`/usr/bin/ps -e | /usr/bin/grep zhm | /usr/bin/sed -e 's/^  *//' -e 's/ .*//'`
	if test "$pid"
	then
		kill $pid
	fi
	;;
*)
	echo "usage: /etc/rc2.d/S90athena {start|stop}"
	;;
esac
