:
#	"@(#)bcheckrc.sh	1.13 91/07/03"
#	Copyright (c) 1984, 1986, 1987, 1988 AT&T
#	Portions Copyright (c) 1990-1991 Altos Computer Systems,
#	Portions Copyright 1988, 1989 The Santa Cruz Operation, Inc
#	All Rights Reserved

#	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
#	The copyright notice above does not evidence any
#	actual or intended publication of such source code.

# ***** This file has those commands necessary to check the file
# system, date, and anything else that should be done before mounting
# the file systems.

#!	chmod +x ${file}



PATH=/bin:/usr/bin:/etc:/altos/bin; export PATH
. /etc/TIMEZONE

usrfs=/dev/usr
if [ "$1" != "-a" ]
then
	[ -x /etc/dumpsave ]  && /etc/dumpsave
fi

rootfs=/dev/root
/etc/fsstat ${rootfs}  >/dev/null 2>&1
if [ $? -ne 0 ]
then
	dofsck=yes
	fsckflags="-s -D -b"
	autoflag=-a				# -a flag to fsck for autoboot
	if [ "$1" != "-a" ]
	then
		autoflag=
		echo "\n\tfsstat: root file system needs checking."
	        echo "\tOK to check the root file system (${rootfs}) (y/n) ? \c"
		while 
			read reply
			[ "$reply" ]
		do
			case $reply in
			n)	dofsck=
				break
				;;
			y)	break
			;;
		*)	echo "\n(y/n)? \c"
			;;
			esac
		done
	fi
	> /lost+found/magic_file; rm /lost+found/magic_file
	[ "$dofsck" ] && 
	/bin/su root -c "/etc/fsck -s -D -b ${autoflag} ${rootfs}"
fi


trap "" 2


# put root into mount table
/bin/su root -c "/etc/devnm /" | grep -v swap | /etc/setmnt
/bin/chmod 644 /etc/mnttab

# check usr file system and attempt to mount if clean.
/etc/fsstat ${usrfs}  >/dev/null 2>&1

if [ $? -ne 0 ]
then
	dofsck=yes
	if [ "$1" != "-a" ]
	then
		echo "\n\tfsstat: usr file system needs checking."
	        echo "\tOK to check the usr file system (${usrfs}) (y/n) ? \c"
		while 
			read reply
			[ "$reply" ]
		do
			case $reply in
			n)	dofsck=
				break
				;;
			y)	break
			;;
		*)	echo "\n(y/n)? \c"
			;;
			esac
		done
	fi
	if [ "$dofsck" ]
	then
        	/bin/su root -c "/etc/fsck -y ${usrfs}"
		/etc/mount ${usrfs} /usr > /dev/null 2>&1
	fi
else		# usr file system is clean so mount
	/etc/mount ${usrfs} /usr > /dev/null 2>&1
fi

# set up ups shutdown parameters from the file /etc/upsparam
if [ -x /altos/bin/upsconfig ]
then
	/altos/bin/upsconfig -i
fi

# clear the restart device
if [ -b /dev/restart ]
then
	echo "\000\000\000\000" >/dev/restart 2>/dev/null
fi

# determine boot status and inform superuser of a UPS operation.
if [ -s /tmp/pfdate -a -x /usr/bin/mailx ]
then
	HOST=`cat /etc/systemid`
	PFDATE=`cat /tmp/pfdate`
	if grep -v "^#" /etc/upsparam | fgrep -i "shutsave" >/dev/null 2>&1
	then
		# a shutsave operation was aborted and normal boot performed
su root -c "/usr/bin/mailx -s shutsave-notice root" <<EOF

Notice from ${HOST}:

A power failure occurred at $PFDATE and a Shutsave operation
was performed to shut the system down.  The restart operation was
aborted and a normal bootstrap was performed instead.

root@$HOST

EOF
	else
		# a shutkill operation was performed
su root -c "/usr/bin/mailx -s shutkill-notice root" <<EOF

Notice from ${HOST}:

A power failure occurred at $PFDATE and a Shutkill operation
was performed to shut the system down.

root@$HOST

EOF
	fi
fi
rm -f /tmp/pfdate

