#! /bin/sh
#
# Copyright (c) 1998-1999 Florian La Roche
#
# /etc/rc.d/boot
#
# this is the first script to be executed from /sbin/init on system startup
#

echo "Running $0."

#
# start a sulogin with a timeout of 30 seconds?
# (add "sulogin=true" to your boot parameters for this)
#
if test -n "$sulogin" ; then
	sulogin -t 30 /dev/tty1
fi

echo "Activating swap-devices in /etc/fstab..."
swapon -a

update

#
# read all configuration parameters
#
. /etc/rc.config

if test -f /fastboot -o -n "$fastboot" -o "$fsck" = no ; then
	echo "Fast boot, no file system check."
else
	echo "Checking file systems..."
	fsck -T -A -a
	if test $? -gt 1 ; then
	    if test -x /etc/rc.d/init.d/kbd ; then
		/etc/rc.d/init.d/kbd start
	    fi
	    echo
	    echo "fsck failed.  Please repair manually and reboot. Please note"
	    echo "that the root file system is currently mounted read-only. To"
	    echo "remount it read-write do:"
	    echo
	    echo "   # mount -n -o remount,rw /"
	    echo
	    echo "CONTROL-D will exit from this shell and reboot the system."
	    echo
	    PS1="(repair filesystem) # "
	    export PS1
	    /sbin/sulogin /dev/tty1
	    echo "Unmounting file systems (ignore error messages)"
	    umount -avr
	    mount -no remount,ro / 2>/dev/null
	    sync
	    reboot -f
	fi
	sync
fi

#
# mount the root filesystem read-write
#
mount -n -o remount,rw /

#
# delete some special files on the root filesystem
#
rm -f etc/mtab /etc/mtab~* /nologin /etc/nologin /fastboot

#
# Mount local filesystems in '/etc/fstab' (and create an entry for /).
#
echo "Mounting local file systems..."
mount -avt nonfs

KRELEASE="`uname -r`"
case "$KRELEASE" in
2.0.*)	;;
*)	mount -t devpts -o gid=5,mode=0620 devpts /dev/pts ;;
esac

# XXX write reboot record here and delete the code in /sbin/init...

#
# We might have mounted something over /dev, see if /dev/initctl is there.
#
if test -p /dev/initctl ; then
	:
else
	rm -f /dev/initctl
	mknod -m 600 /dev/initctl p
	kill -USR1 1
fi

#
# enable it to make the kernel more secure
#
if test -f /proc/sys/net/ipv4/tcp_syncookies ; then
	echo 1 > /proc/sys/net/ipv4/tcp_syncookies
fi

#
# if we have kernel modules create the 'modules.dep' file by
# calling 'depmod' and start kerneld for kernel 2.0.
#
if test "$START_KERNELD" = yes -a -f /proc/ksyms ; then
	/sbin/depmod -a
	test -f /proc/sys/kernel/modprobe || /sbin/kerneld
fi

#
# start the loopback device
#
ifconfig lo 127.0.0.1
route add -net 127.0.0.0 netmask 255.0.0.0 dev lo

#
# set host- and domainname
#
if test -n "$FQHOSTNAME" ; then
	hostname $FQHOSTNAME
fi
if test -n "$YP_DOMAINNAME" ; then
	domainname $YP_DOMAINNAME
fi

#
# The kernel sets the time to UTC. If you want to have local time
# in the hardware clock, the correct time must be set here.
#
if test -z "$GMT" ; then
	hwclock --hctosys
fi

#
# remove lock-files and *.pid-files
#
rm -f /var/lock/* /tmp/.X*lock /var/run/* 2>/dev/null

#
# create a new utmp
#
: > /var/run/utmp
chmod 664 /var/run/utmp
chown root:tty /var/run/utmp

#
# this is at least needed for lsof
#
RELEASE="System.map-$KRELEASE"
if test -f /boot/$RELEASE ; then
	test -L /boot/System.map && ln -sf $RELEASE /boot/System.map
	test -e /boot/System.map || ln -sf $RELEASE /boot/System.map
fi

#
# The following script is executed at boot-up and also from a cron-entry
# in the early morning. So your system should be checked often enough.
#
if test -x /etc/cron.daily ; then
	/etc/cron.daily STARTUP
fi

#
# Read all kernel messages generated until now and put them in one file.
#
if test -x /usr/sbin/klogd ; then
	# keep the messages from the last boot for debugging purposes
	if test -f /var/log/boot.msg ; then
		mv /var/log/boot.msg /var/log/boot.msg.old
	fi
	/usr/sbin/klogd -x -f /var/log/boot.msg -o
fi

#
# file for local additions
#
if test -x /etc/rc.d/boot.local ; then
	/etc/rc.d/boot.local
fi

exit 0
