bugfixed boot script, udev init script, cups and shadow package
[hdw-linux/hdw-linux.git] / misc / sysfiles / etc / init.d / boot
1 #!/bin/sh
2 #
3 # hdw - linux /etc/init.d/boot (copied from ROCK Linux + modifications)
4 #
5 # lowlevel bootup script
6 #
7
8 exec 2>&1
9
10 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
11
12 echo "** booting hdw-linux... **"
13
14 . /etc/conf/bootdown
15 [ -f /fastboot ] && FASTBOOT=1 ; [ -f /forcefsck ] && FORCEFSCK=1
16 if [ $FORCEFSCK = 1 ] ; then echo "going to force fsck" ; FASTBOOT=0 ; fi
17 [ $FASTBOOT = 1 ] && echo "fast boot mode enabled"
18
19 mount -v -n /dev
20 mount -v -n /proc ; mount -v -n /sys
21
22 echo "loading kernel modules and configuring the kernel ..."
23 . /etc/conf/kernel
24
25 echo "populating device nodes ..."
26 /etc/init.d/udev start
27
28 if [ -f /etc/conf/devfs ] ; then
29         echo "configuring device nodes ..."
30         . /etc/conf/devfs
31 fi
32
33 echo "activating swap-devices ..."
34 swapon -a
35
36 if [ $FASTBOOT != 1 ]
37 then
38         echo "checking file systems (1/3) ..."
39         mount -n -o remount,ro /
40         if [ $FORCEFSCK = 1 ]
41         then fsck -A -C -a -f ; fsckrc=$? ; sync ; sleep 3
42         else fsck -A -C -a    ; fsckrc=$? ; sync ; sleep 3
43         fi
44         x=2
45         [ $fsckrc -eq 1 -a $EASYFSCK = 1 ] && fsckrc=0
46         while [ $fsckrc -eq 1 -a $x -lt 4 ]
47         do
48                 echo "filesystem check modified disks!"
49                 echo "checking file systems ($x/3) ..."
50                 fsck -A -C -a -f ; fsckrc=$? ; sync ; sleep 3
51                 if [ $x -eq 3 ] ; then x=4 ; else x=3 ; fi
52         done
53         if [ $fsckrc -eq 0 ]
54         then
55                 echo "all checked filesystems are clear."
56                 if [ $x != 2 ] ; then
57                         echo " **"
58                         echo " ** filesystem check modified disks."
59                         echo " **"
60                         echo " ** going to reboot the system."
61                         echo " **"
62                         for x in 10 9 8 7 6 5 4 3 2 ; do
63                                 echo -en "\rsystem reboot in $x seconds ... "
64                                 sleep 1
65                         done ; echo -e "\rsystem reboot now!                 "
66                         /sbin/reboot -d -f
67                         exit
68                 fi
69         else
70                 echo " **"
71                 echo " ** filesystem check failed (returncode=$fsckrc)."
72                 echo " ** please repair the broken disk(s) manually."
73                 echo " **"
74                 echo " ** note: The kernel parameter '-b' can be used to boot"
75                 echo " ** directly into a single-user login shell."
76                 echo " **"
77                 echo " ** going to reboot the system."
78                 echo " **"
79                 for x in 10 9 8 7 6 5 4 3 2 ; do
80                         echo -en "\rsystem reboot in $x seconds ... "
81                         sleep 1
82                 done ; echo -e "\rsystem reboot now!                 "
83                 /sbin/reboot -d -f
84                 exit
85         fi
86 fi
87
88 mount -v -n -o remount,rw /
89 grep -E -v '^none (/|[a-z]+:) ' /proc/mounts > /etc/mtab
90 mount -v -a -t nocoda,nfs
91
92 if type hostname > /dev/null 2>&1
93 then
94         echo "set the hostname to [`cat /etc/HOSTNAME`] ..."
95         hostname `cat /etc/HOSTNAME`
96 else
97         echo "hostname not set: no 'hostname' command found"
98 fi
99
100 echo "refresh utmp, delete lock files and other stuff ..."
101 rm -f /var/lock/* /var/lock/*/* /var/run/* 2> /dev/null
102 touch /var/run/utmp ; chmod 664 /var/run/utmp ; chown root.tty /var/run/utmp
103 rm -f /etc/nologin /nologin /fastboot /forcefsck /fastdown
104
105 if [ "$TEMPCLEAN" = 1 ] ; then
106         echo "cleaning up /tmp ..."
107         for x in /tmp/* /tmp/.[!.]* ; do
108                 if [ -O "$x" ] ; then
109                         [ "$x" != "/tmp/lost+found" ] &&
110                         [ "$x" != "/tmp/quota.user" ] &&
111                         [ "$x" != "/tmp/quota.group" ] &&
112                         rm -rf -- "$x"
113                 else
114                         rm -rf -- "$x"
115                 fi
116         done
117 fi
118
119 if type klogd > /dev/null 2>&1
120 then
121         echo "writing /var/log/boot.msg ..."
122         klogd -f /var/log/boot.new -o
123         grep '.' < /var/log/boot.new > /var/log/boot.msg
124         rm /var/log/boot.new
125 else
126         echo "kernel boot messages are not logged: no 'klogd' command found."
127 fi
128
129 if type loadkeys > /dev/null 2>&1
130 then
131         echo "set the keyboard keymappings ..."
132         if [ -L /etc/default.keymap ] ; then
133                 oldpwd="`pwd`" ; cd /etc
134                 loadkeys `ls -l default.keymap | tr -s ' ' | cut -f11 -d' '`
135                 cd "$oldpwd" ; unset oldpwd
136         elif [ -f /etc/default.keymap ] ; then
137                 loadkeys /etc/default.keymap
138         else
139                 echo "no /etc/default.keymap found."
140         fi
141 else
142         echo "keymappings not configured: no 'loadkeys' command found."
143 fi
144
145 if type ifconfig > /dev/null 2>&1
146 then
147         echo "setting up loopback networking ..."
148         ifconfig lo 127.0.0.1 netmask 255.0.0.0 up
149         route add -net 127.0.0.0 netmask 255.0.0.0 dev lo
150 fi
151
152 echo 'setting overflow UID and GID kernel parameters ...'
153 sysctl -w kernel.overflowuid=`id -u nobody` | tr -d '\n'
154 echo -n ', ' ; sysctl -w kernel.overflowgid=`id -g nobody`
155
156 echo "initializing kernel random number generator ..."
157 [ -f /var/state/random-seed ] && cat /var/state/random-seed >/dev/urandom
158 dd if=/dev/urandom of=/var/state/random-seed count=1 2> /dev/null
159
160 # write EOT mark for btee
161 echo -ne '\004'