#
# 5799-WZQ (C) COPYRIGHT IBM CORPORATION 1988
# LICENSED MATERIALS - PROPERTY OF IBM
# REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
#
# $Header:rc 12.1$ 
# $ACIS:rc 12.1$ 
# $Source: /ibm/acis/usr/src/etc/RCS/rc,v $ 

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

#
# "test" is used here on purpose, and not "[".  On
# the minimal systems, "[" does not exist at this point.
#
if test -r /etc/rc.config; then
	. /etc/rc.config
fi

#
# Important Note:
#
# Most of the facilities set up by this file can be controlled
# by changing lines in /etc/rc.config. Wherever possible change
# the definitions in /etc/rc.config rather than here.
#
network="${network-un0}"		# primary network
use_nfs="${use_nfs-yes}"		# if using NFS kernel & utilities
system_type=${system_type-full}
rc_start="${rc_start}"			# rc hook
rc_end="${rc_end}"			# rc end hook
use_lpd="${use_lpd-yes}"		# if we start lpd
use_pp4216="${use_pp4216-yes}"		# if we load pp4216 microcode
use_dfs="${use_dfs-yes}"		# if we mount dos file systems
ipl_cpu="${ipl_cpu}"			# If there are any seconday processors


# hook at start of rc; done before everything except macro definitions
eval "${rc_start}"


# If minimal system, then get the network started and mount
# the /root file system.
case "${system_type}" in
minimal|nfsminimal)
	/etc/minimal/mount_root || exit 1;;
esac

if [ -f /fastboot ]
then
	echo Fast boot ... skipping disk checks >/dev/console
elif [ $1x = autobootx ]
then
	echo Automatic reboot in progress... >/dev/console
	date >/dev/console
	/etc/fsck -p >/dev/console
	status=$?
	case $status in
	0)
		date >/dev/console
		;;
	2)
		exit 1
		;;
	4)
		/etc/reboot -n
		;;
	8)
		echo "Automatic reboot failed... help!" >/dev/console
		exit 1
		;;
	12)
		echo "Reboot interrupted" >/dev/console
		exit 1
		;;
	*)
		echo "Unknown fsck error ($status) in reboot" > /dev/console
		exit 1
		;;
	esac
else
	date >/dev/console
fi

# attempt to rationally recover the passwd file if needed
if [ -s /etc/ptmp ]
then
	if [ -s /etc/passwd ]
	then
		ls -l /etc/passwd /etc/ptmp >/dev/console
		rm -f /etc/ptmp		# should really remove the shorter
	else
		echo 'passwd file recovered from ptmp' >/dev/console
		mv /etc/ptmp /etc/passwd
	fi
elif [ -r /etc/ptmp ]
then
	echo 'removing passwd lock file' >/dev/console
	rm -f /etc/ptmp
fi


/etc/umount -at afs
/etc/umount -a
case "${system_type}" in
minimal|nfsminimal) :;;
*)
	cp /dev/null /etc/mtab
	case "${use_nfs}" in
	yes)
		/etc/mount -fv /			>/dev/console 2>&1;;
	esac;;
esac
case "${use_nfs}" in
yes)
	/etc/mount -atv ufs				>/dev/console 2>&1;;
*)
	/etc/mount -a					>/dev/console 2>&1;;
esac
case "${use_dfs}" in
yes)
	/etc/mount -atv dfs				>/dev/console 2>&1;;
esac
/etc/swapon -a						>/dev/console 2>&1

if [ -f /fastboot ]      
then
	rm -f /fastboot
else
	if [ -d /vice/file ]; then
		echo Force file system salvage >/dev/console
		rm /vice/file/SHUTDOWN >/dev/null 2>&1 ||
			touch /vice/file/FULLSALVAGE
	fi
fi

				echo -n 'checking quotas:' >/dev/console
/etc/quotacheck -a -p					>/dev/console 2>&1
				echo ' done.'		>/dev/console
/etc/quotaon -a

case "${system_type}" in
minimal|nfsminimal) :;;
*)
	/bin/ps -U					>/dev/console 2>&1;;
esac

rm -f /etc/nologin
rm -f /usr/spool/uucp/LCK.*
chmod 666 /dev/tty[pqrs]*

# use -$- to pass along debugging flags such as -x or -v
sh -$- /etc/rc.local

				echo preserving editor files 	>/dev/console
(cd /tmp; /usr/lib/ex3.7preserve -a)
				echo clearing /tmp 		>/dev/console
(cd /tmp; find . ! -name . ! -name lost+found ! -name quotas ! -name salvage\* -exec rm -r {} \; )

				echo -n standard daemons:	>/dev/console
/etc/update;			echo -n ' update'		>/dev/console
/etc/cron;			echo -n ' cron'			>/dev/console

case "${system_type}" in
full)
	/etc/accton /usr/adm/acct;
	echo -n ' accounting'				>/dev/console;;
esac

case "${use_pp4216}" in
yes)
	if [ -f /usr/lib/pp4216/ppsadapt.mod ]; then
		/usr/lib/pp4216/ldps /usr/lib/pp4216/ppsadapt.mod >/dev/console 2>&1
		echo -n ' pp4216'				>/dev/console
	fi;;
esac

case "${use_lpd}" in
yes)
	if [ -f /usr/lib/lpd ]; then
		rm -f /dev/printer
		/usr/lib/lpd;		echo -n ' printer'	>/dev/console
	fi;;
esac
				echo '.'			>/dev/console

# we only start rwhod if we're on a real network; inetd is always
# started
echo -n starting network daemons:				>/dev/console
case "${network}" in
"") :;;
*)
	if [ -f /etc/rwhod ]; then
		/etc/rwhod;		echo -n ' rwhod'	>/dev/console
	fi;;
esac

if [ -f /etc/inetd ]; then
	/etc/inetd;		echo -n ' inetd'		>/dev/console
fi
				echo '.'			>/dev/console

				date				>/dev/console

# Start up secondary CPU(s).
case "${ipl_cpu}" in
"") :;;
*)  echo -n "Starting slave CPU(s)..."				>/dev/console
    /etc/ipl ${ipl_cpu}						>/dev/console
esac

# hook at end of rc
eval "${rc_end}"

exit 0
