#! /bin/sh
#
# |-----------------------------------------------------------|
# | Copyright (c) 1991, 1990 MIPS Computer Systems, Inc.      |
# | All Rights Reserved                                       |
# |-----------------------------------------------------------|
# |          Restricted Rights Legend                         |
# | Use, duplication, or disclosure by the Government is      |
# | subject to restrictions as set forth in                   |
# | subparagraph (c)(1)(ii) of the Rights in Technical        |
# | Data and Computer Software Clause of DFARS 252.227-7013.  |
# |         MIPS Computer Systems, Inc.                       |
# |         950 DeGuigne Avenue                               |
# |         Sunnyvale, California 94088-3650, USA             |
# |-----------------------------------------------------------|
#
# $Header: rc2,v 1.12.2.1 92/06/24 13:35:49 marker Exp $

#	"Run Commands" executed when the system is changing to init state 2,
#	traditionally called "multi-user".
#
# NOTE: Any shells executed by the for-loops should return:
#		0 : normal execution
#		1 : bad/irregular usage
#		2+: catastrophic error, don't continue

# So created files (*.pid, log files, etc) will not be world writable
umask 002

. /etc/TIMEZONE

#	Pickup start-up packages for mounts, daemons, services, etc.
set `who -r`
if [ $9 = "S" ]
then
	echo 'The system is coming up.  Please wait.'
	BOOT=yes
	if [ -f /etc/rc.d/PRESERVE ]	# historical segment for vi and ex
	then
		mv /etc/rc.d/PRESERVE /etc/init.d
		ln /etc/init.d/PRESERVE /etc/rc2.d/S02PRESERVE
	fi

elif [ $7 = "2" ]
then
	echo 'Changing to state 2.'
	if [ -d /etc/rc2.d ]
	then
		for f in /etc/rc2.d/K*
		{
			if [ -s ${f} ]
			then
				/bin/sh ${f} stop
				_exit=$?
				if [ $_exit -gt 1 ]; then
					exit $_exit
				fi
			fi
		}
	fi
fi

if [ -d /etc/rc2.d ]
then
	for f in /etc/rc2.d/S*
	{
		if [ -s ${f} ]
		then
			/bin/sh ${f} start
			_exit=$?
			if [ $_exit -gt 1 ]; then
				exit $_exit
			fi
		fi
	}
fi
if [ "${BOOT}" = "yes" ]
then
	stty sane clocal tab3 2>/dev/null
fi

if [ "${BOOT}" = "yes" -a -d /etc/rc.d ]
then
	for f in `ls /etc/rc.d`
	{
		if [ ! -s /etc/init.d/${f} ]
		then
			/bin/sh /etc/rc.d/${f}
			_exit=$?
			if [ $_exit -gt 1 ]; then
				exit $_exit
			fi
		fi
	}
fi

if [ "${BOOT}" = "yes" -a $7 = "2" ]
then
	echo 'The system is ready.'
elif [ $7 = "2" ]
then
	echo 'Change to state 2 has been completed.'
fi
