#! /bin/sh
#
# /etc/init.d/boot
#
# These commands are executed at boot time by init(8).
#
# (c) some unknown man in a dark history
# (c) 1996-1999 Pavel Troler <patrol@sinus.cz>
# (c) 1999-2000 Petr Baudis <pasky@pasky.ji.cz>
#

PATH=/sbin:/usr/sbin:/bin:/usr/bin

# Crash system now, before we can do anything harmful, with devfsd.
# We must do it before everything else, because somebody might found
# very funny to require something what we have to emulate because we
# will start to do so...
if [ -x /sbin/devfsd ]; then
  /sbin/devfsd /dev
  . /etc/init.d/devfs.files
else
  echo "Devfsd is missing! You may encounter serious problems..."
  echo "Try to boot with lilo parameter init=/bin/bash and fix it."
fi

# Enable swapping
/sbin/swapon -a

# Y2K bug fix
# We've to do this so early in order to prevent clock skew e.g.
# in modules area...
. /etc/init.d/y2k

# Start the kernel daemon for autoload of modules.
if [ -x /sbin/kerneld ]; then
  /sbin/kerneld
else
  echo "You don't have even /sbin/kerneld! Don't wait for"
  echo "autoloading of some nasty things..."
fi

# Test to see if the root partition is read-only, like it ought to be.
READWRITE=no
if echo -n >> "Testing filesystem status"; then
 rm -f "Testing filesystem status"
 READWRITE=yes
fi

# Check the integrity of all filesystems
if [ ! $READWRITE = yes ]; then
 /sbin/fsck -A -a
 if [ $? -gt 0 ] ; then
  echo
  echo
  echo "*****************************************"
  echo "fsck returned error code - REBOOTING NOW!"
  echo "*****************************************"
  echo
  echo
  /sbin/reboot 
 fi
 # Remount the root filesystem in read-write mode
 echo "Remounting root device with read-write enabled."
 /sbin/mount -w -n -o remount /
else
 cat << EOF

*** Root partition has already been mounted read-write. 
*** Please configure Your setup correctly using rdev or lilo
*** and reboot Your system.

EOF
 sleep 3
fi

echo "The system is coming up. Please wait..."

# The following will come handy when booting a new kernel for the first time
if [ -x /sbin/depmod ]; then
  /sbin/depmod -a
else
  echo "Oh, we don't have /sbin/depmod - you might found";
  echo "your modules dependencies broken."
fi
rm -f /lib/modules/current; ln -s /lib/modules/`uname -r` /lib/modules/current;

# Start update daemon
/sbin/update

# Remove /etc/mtab* so that mount will create it with a root entry
rm -f /etc/mtab* /etc/nologin /etc/utmp

# Basic system data (hostname etc.)
hostname `cat /etc/HOSTNAME | cut -f1 -d .`
domainname `cat /etc/HOSTNAME | cut -f2- -d .`
# hostname `cat /etc/HOSTNAME`

# Looks like we have to create this.
cat /dev/null > /var/run/utmp
cat /dev/null > /var/run/utmpx

echo "Removing stale locks and pids..."
rm -f /var/run/*pid* > /dev/null
rm -f /var/lock/* > /dev/null
rm -f /var/lock/subsys/* > /dev/null

# mount file systems in fstab (and create an entry for /)
# but not NFS because TCP/IP is not yet configured
echo "Mounting local file systems..."
/sbin/mount -avt nonfs

# Configure the system clock.
# This can be changed if your system keeps GMT.
if [ -x /sbin/clock ]; then
  echo "Setting the system clock from CMOS..."
  /sbin/clock -s -u
else
  echo "Your system clock was kept untouched from CMOS..."
fi

if [ -x /usr/bin/tickadj -a -r /etc/tickadj ]; then
  echo "Adjusting system tick value..."
  /usr/bin/tickadj `cat /etc/tickadj`
fi

# Set screen blanking timeout to 20 minutes.
setterm -blank 20 -powersave on

#Check if the font setup file is present, and execute it.
if [ -x /etc/init.d/font ]; then
   /etc/init.d/font
fi

# Turn the disk quota system ON.
if [ -x /usr/sbin/quotaon ]; then
  echo "Turning the system quotas ON..."
  /usr/sbin/quotaon -avu
fi

# Turn the user accounting ON.
if [ -x /usr/sbin/accton ]; then
  echo "Turning the system accounting ON..."
  /usr/sbin/accton /var/adm/acct
fi

# Setup the /etc/issue to reflect the current kernel level:
# THESE WIPE ANY CHANGES YOU MAKE TO /ETC/ISSUE WITH EACH
# BOOT. COMMENT IT OUT IF YOU WANT TO MAKE CUSTOM VERSIONS.
# Now there's no need to do this, you can have logo in
# /etc/logo - it will be put on the top of system informations.
echo -en "\033c" >/etc/issue
if [ -r /etc/logo ]; then
  cat /etc/logo >>/etc/issue
fi
echo "`cat /etc/release` (Linux `uname -a | cut -d\  -f3`) UNIX (`/bin/hostname`) [\\l]" >> /etc/issue
echo >> /etc/issue

echo >/etc/issue.net
echo "`cat /etc/release` (%s %r) at %h [pts/%t] ready." >>/etc/issue.net
echo "Local time is %d" >>/etc/issue.net

# Set up the serial ports.
if [ -x /etc/init.d/serial ]; then
  echo "Setting the serial ports..."
  /etc/init.d/serial
fi

# And start ls to pre-scan root DOS directories
/bin/ls -l /dos/c >/dev/null &
/bin/ls -l /dos/c/games >/dev/null &
/bin/ls -l /dos/c/tp7/programs >/dev/null &
/bin/ls -l /dos/z >/dev/null &
