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

  # Set the path.
  PATH=/sbin:/etc:/bin:/usr/bin

  # Get swap up as fast as possible.
  echo "Turning on swap (for swapping to partitions)"
  swapon -a

  # See if filesystems need checking.
  # With the newest fsck and minix or ext2 filesystems, the
  # "-f /etc/fastboot" clause can be deleted.
  if [ ! -f /etc/fastboot ]
  then
	echo "No fastboot, checking all file systems"
	fsck -AV -a
	# 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.
		PS1="(Repair filesystem) #"; export PS1

		# Now try to execute a shell, in preferred order.
		if [ -x /etc/su-shell ]; then /etc/sushell
		elif [ -x /sbin/sulogin ]; then /sbin/sulogin
		else /bin/sh; fi

		# And reboot the system when done.
		echo "Automatic reboot in progress."
		reboot
	fi
  fi

  # Remount the root fileystem read-write.
  echo "Re-mounting root file system read-write"
  mount -n -o remount,rw /

  # Be sure /etc/mtab and /etc/utmp are up to date.
  rm -f /etc/mtab~ /etc/fastboot /etc/nologin
  > /etc/utmp
  > /etc/mtab
  mount -f /

  # Initialize serial ports.
  if [ -f /etc/rc.d/rc.serial ]
  then
	. /etc/rc.d/rc.serial
  fi

  # Set the hostname.
  #
  #  ** WARNING ** dependant on your setup, you might need to add
  #                a '-S' to the hostname call, or remove it
  #		   completely if your prefer to do it in rc.net1.
  #
  if [ -f /etc/HOSTNAME ]
  then
	# Find out if there's a full hostname here.
	full=`cat /etc/HOSTNAME`
	if [ "${full#*.}" != "" ]
	then
		# Yes, set both host and domainname from it (new style).
  		hostname ${full%%.*}
  		domainname ${full#*.}
	else
		# No, so stuff whole FQDN into hostname (old style).
  		hostname -Sf "$full"
	fi
  else
	hostname linux
	domainname nodomain.org
  fi
  echo "The name of this system is `hostname`"

  # First step in setting up the net subsystem.
  if [ -f /etc/rc.d/rc.net1 ]
  then
	. /etc/rc.d/rc.net1
  fi

  # Any local setup procedures ?
  if [ -f /etc/rc.d/rc.local ] 
  then
	. /etc/rc.d/rc.local
  fi

  # All done.
