#! /bin/sh
#
# Copyright (c) 1996 S.u.S.E. GmbH Fuerth, Germany.  All rights reserved.
#
# Author: Florian La Roche <florian@suse.de>, 1996
#	  Werner Fink <werner@suse.de>, 1996
#         Burchard Steinbild <bs@suse.de>, 1996
# Hacked by Koblinger Egmont <egmont@fazekas.hu>
#
# /sbin/init.d/boot
#
# first script to be executed from init on system startup
#

. /etc/rc.config
echo "Running $0."

#
# start UPS daemon
#
if test "$START_DUMBUPSD" = yes ; then
    /sbin/init.d/dumbupsd start
fi

#
# bring up local filesystems
#
/sbin/init.d/filesystem start

#
# store pidfile for dumbupsd
#
if test "$START_DUMBUPSD" = yes ; then
    /sbin/init.d/dumbupsd usr1
fi

#
# initialize database for kerneld.  This should be done earlier, but
# could cause a lot of trouble with damaged file systems.
# restart of kerneld will be done by /sbin/init.d/kerneld
# 
MODULES_DIR=/lib/modules/`uname -r` 
if test "$START_KERNELD" = yes -a \
        -x /sbin/depmod -a ! -e /proc/sys/kernel/modprobe ; then
    if test -d $MODULES_DIR ; then
        /sbin/depmod -a 2> /dev/null > /dev/null
    fi
fi


# Let ld.so rebuild its cache.
test -x /sbin/ldconfig && /sbin/ldconfig -X 2>/dev/null

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

#
# initialize loopback device
#
if test "$START_LOOPBACK" = yes; then
	ifconfig lo 127.0.0.1 netmask 255.0.0.0 up
	route add -net 127.0.0.0 netmask 255.0.0.0 dev lo
fi

#
# start bootup client scripts.
#
if test -d /sbin/init.d/boot.d; then
	for i in /sbin/init.d/boot.d/S*; do
		test -f "$i" && /bin/sh $i b
	done
fi

#
# set hostname and domainname
#
test -n "$FQHOSTNAME" && hostname ${FQHOSTNAME%%.*}
test -n "$YP_DOMAINNAME" && domainname $YP_DOMAINNAME


# set and adjust the CMOS clock
test "$GMT" != "YAST_ASK" && hwclock -s $GMT
test -f /etc/adjtime || echo "0.0 0 0.0" > /etc/adjtime
test "$GMT" != "YAST_ASK"  -a "$START_XNTPD" != "yes" && hwclock -a $GMT

#
# clean up
#
rm -f /var/run/utmp
echo -n > /var/run/utmp
chmod 664 /var/run/utmp
chown root.tty /var/run/utmp

rm -f /var/lock/* /var/lock/*/* /tmp/.X*lock \
      /var/run/syslogd.pid /var/spool/uucp/LCK* 2>/dev/null

# 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 /root/bin/cron.daily; then
#	/root/bin/cron.daily
#fi

#
# start user defined bootup script.
#
if test -f /sbin/init.d/boot.local ; then
	/bin/sh /sbin/init.d/boot.local
fi

# Read all kernel messages generated until now and put them in one file.
if test -x /usr/sbin/klogd ; then
	/usr/sbin/klogd -f /var/log/boot.msg -o
	/bin/sleep 1
fi

#
# setup PNP if config file is present
#
if test -r /etc/isapnp.conf -a -x /sbin/isapnp ; then
    echo "Initializing PnP devices."
    /sbin/isapnp /etc/isapnp.conf
fi

#
# enable DEXE binary format
#
if test -d /proc/sys/fs/binfmt_misc ; then
  echo "Registering DEXE for binfmt..."
  ( cd /proc/sys/fs/binfmt_misc; \
    echo :DEXE:M::\\x0eDEXE::/usr/bin/dosexec: >register )
fi

#
# insert memstat module for xosview
#
if test -f $MODULES_DIR/misc/memstat.o ; then
    echo Loading memstat module...
    insmod $MODULES_DIR/misc/memstat.o
fi

#
# look for stuff to do for first bootup.
#
if test -e /var/adm/setup/setup.newinst -o -e /usr/lib/YaST/.configured2 ; then
    if test -w / -a "$NO_AUTO_SETUP" != true ; then
        if test -e /usr/lib/YaST/.configured2 ; then
            echo
            echo It seems, that last installation setup has not been finished...
            echo To be sure, it will be started again.
            echo
            sleep 2
            rm -f /usr/lib/YaST/.configured2
        fi
        /lib/YaST/bootsetup
        #
        # maybe YaST has started gpm. This can lead into trouble with
        # setserial.  Since it is started again, when entering into
        # runlevel 2, we can kill it here.
        #
        killproc -TERM /usr/bin/gpm > /dev/null 2> /dev/null
    fi
fi

exit 0
