minimal fixes ;) - should work now - semi automatic :))
[hdw-linux/hdw-linux.git] / misc / fai / fai_rc
1 #!/bin/sh
2 #
3 # hdw - linux /etc/init.d/rc (modified for fai)
4 #
5 # controls switching of runlevels       (copied from ROCK Linux)
6 #
7
8 exec 2>&1
9
10 export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/fai/scripts
11
12 echo "** running rc (fai) script **"
13
14 echo "RC: Previous runlevel: $PREVLEVEL, current runlevel: $RUNLEVEL."
15
16 curdir=/etc/init.d/rc$RUNLEVEL.d
17 prevdir=/etc/init.d/rc$PREVLEVEL.d
18
19 #
20 # run the KILL scripts of the previous runlevel (if needed)
21 #
22 if ! [ $PREVLEVEL = S -o $PREVLEVEL = N ]
23 then
24         echo "RC: Leave runlevel $PREVLEVEL ..."
25         for i in $prevdir/K*; do
26                 test -x "$i" || continue
27                 x="`echo "$i" | sed "s,$prevdir/K..,$curdir/S??,"`"
28                 [ "`echo $x`" = "$x" ] || continue ; unset x
29                 $i stop < /dev/null
30         done
31 fi
32
33 echo "RC: Enter runlevel $RUNLEVEL ..."
34
35 if [ $RUNLEVEL = S ]
36 then
37         #
38         # Kill all processes
39         #
40         echo "Sending all processes a SIGTERM (15) ..."
41         killall5 -15
42         sleep 5
43         echo "Sending all processes a 2nd SIGTERM (15) ..."
44         killall5 -15
45         sleep 3
46         echo "Sending all processes a SIGKILL (9) ..."
47         killall5 -9
48         sleep 3
49 elif [ $RUNLEVEL = 0 -o $RUNLEVEL = 6 ]
50 then
51         #
52         # shut down the system
53         #
54         if [ $RUNLEVEL = 0 ] ; then
55         mode=halt ; else mode=reboot ; fi
56         /etc/init.d/down $mode
57         exit 0
58 else
59         #
60         # run the START scripts of the current (new) runlevel
61         #
62         for i in $curdir/S*; do
63                 test -x "$i" || continue
64                 x="`echo "$i" | sed "s,$curdir/S..,$prevdir/K??,"`"
65                 [ "`echo $x`" = "$x" ] || continue ; unset x
66                 $i start < /dev/null
67         done
68 fi
69
70 echo "mounting fai config space ..."
71 FAI_MOUNT_LINE
72 echo "done"
73
74 echo "executing rc_fai.sh script ..."
75 /fai/scripts/rc_fai.sh
76 echo
77
78 if [ -f /tmp/fai_finished ] ; then
79         echo
80         echo "FAI finished - congrats :)"
81         echo
82         echo "you may login as root (passwd = hdw), chroot to /trg and"
83         echo "do further modifications."
84         echo
85 else
86         echo "login: root | passwd = hdw"
87 fi
88
89 exit 0