#!/bin/sh

# Set the path
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH

echo 'Loading default keymap'
loadkeys /etc/sysconfig/console/default.kmap < /dev/tty0 > /dev/tty0 2>/dev/null

echo 'Activating swap partitions'
swapon -a

echo 'Set hostname'
hostname pb.claudio.ch

echo 'Checking root filesystem'
initlog -c "fsck -T -a /"
rc=$?
# A return of 2 or higher means there were serious problems.
if [ $rc -gt 1 ]; then
 echo
 echo
 echo "*** An error occurred during the file system check."
 echo "*** Dropping you to a shell; the system will reboot"
 echo "*** when you leave the shell."

 PS1="(Repair filesystem) \#"; export PS1
 sulogin

 echo "Unmounting file systems"
 umount -a
 mount -n -o remount,ro /
 echo "Automatic reboot in progress."
 reboot
fi

echo 'mount /proc'
mount -t proc /proc /proc

echo 'Remounting root filesystem in read-write mode'
mount -n -o remount,rw /

echo 'Set clock'
/sbin/clock -a

echo 'Reset mtab'
>/etc/mtab
mount -f /
mount -f /proc

echo 'Modules'
depmod -a

if [ -f /proc/sys/kernel/modprobe ]; then
 echo '/sbin/modprobe' >/proc/sys/kernel/modprobe
fi

echo 'Checking and mounting filesystems'
initlog -c "fsck -T -R -A -a"
rc=$?
# A return of 2 or higher means there were serious problems.
if [ $rc -gt 1 ]; then
 echo
 echo
 echo "*** An error occurred during the file system check."
 echo "*** Dropping you to a shell; the system will reboot"
 echo "*** when you leave the shell."

 PS1="(Repair filesystem) \#"; export PS1
 sulogin

 echo "Unmounting file systems"
 umount -a
 mount -n -o remount,ro /
 echo "Automatic reboot in progress."
 reboot
fi

mount -a -t noproc

echo 'Clean out /etc, utmp, wtmp, pid and lock files.'
rm -f /etc/mtab~ /fastboot /fsckoptions /forcefsck

>/var/run/utmp
touch /var/log/wtmp
chgrp utmp /var/run/utmp /var/log/wtmp
chmod 0664 /var/run/utmp /var/log/wtmp

rm -f /var/run/*.pid

rm -f /var/lock/console.lock
rm -f /var/lock/console/*
rm -f /var/lock/LCK*
rm -f /var/lock/subsys/*
rm -f /tmp/.X*-lock

# Now that we have all of our basic modules loaded and the kernel going,
# let's dump the syslog ring somewhere so we can find it later
dmesg > /var/log/dmesg
