#!/sbin/sh
#
# checkfsys	This script is run when the system comes up for
#		the first time. It takes care of checking file
#		systems.
#
# Version:	@(#) /sbin/init.d/checkfsys  1.50 1994-01-18
#
# Author:	Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#

  # See how we were called.
  case "$1" in
    bcheckrc)
	# Maybe
	swapon -a
	/bin/mount  -nt proc /proc /proc
	/bin/mount  -no remount,ro /
	/sbin/update

  	# See if filesystems need checking.
  	if [ ! -f /etc/fastboot ]; then
		echo "Bcheckrc: No fastboot, checking all file systems"
		fsck -Aa
		# Exit status of 4 or greater means something went wrong.
		if [ $? -gt 3 ]; then
		   # Oh-oh. Repair manually, and reboot.
		   echo "*** File system check failed, please repair by hand"
		   echo "*** Dropping you in a shell. Please reboot after"
		   echo "*** repairing the file system."
		   echo "*** Remember the root file system can still be readonly!"

		   # Set a suitable prompt.
		   export PS1="(Repair filesystem) #"

		   # Now try to execute a shell, in preferred order.
		   if [ -x /bin/login ]; then
			stty 9600 sane cr0 tab3 pass8 ek
			/bin/mount  -no remount,ro /usr
			/bin/login root
		   else
			/bin/tcsh -f
		   fi

		   # And reboot the system when done.
		   echo "Automatic reboot in progress."
		   reboot -f
		fi
	fi
        ;;
    *)
        # Oops someone made a typo.
        echo "Usage: /sbin/init.d/checkfsys {bcheckrc}"
        exit 1
  esac

exit 0
