c69e387bf9a11b33f808a95e9c6556e2a4dedec0
[live-boot-grml.git] / debian / casper.init
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          casper
4 # Required-Start:    $syslog
5 # Required-Stop:     $syslog
6 # Should-Start:      $local_fs
7 # Should-Stop:       $local_fs
8 # Default-Start:     1 2 3 4 5
9 # Default-Stop:      0 6
10 # Short-Description: Casper init script
11 # Description:       Does the proper shutdown in a casper booted system.
12 ### END INIT INFO
13
14 # Author: Tollef Fog Heen <tfheen@canonical.com>
15 #         Marco Amadori <marco.amadori@gmail.com>
16 #
17 PATH=/usr/sbin:/usr/bin:/sbin:/bin
18 NAME=casper
19 SCRIPTNAME=/etc/init.d/$NAME
20
21 # Exit if system was not booted by casper
22 grep -qs boot=casper /proc/cmdline || exit 0
23
24 # Read configuration variable file if it is present
25 [ -r /etc/$NAME.conf ] && . /etc/$NAME.conf
26
27 # Load the VERBOSE setting and other rcS variables
28 [ -f /etc/default/rcS ] && . /etc/default/rcS
29
30 # Define LSB log_* functions.
31 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
32 . /lib/lsb/init-functions
33
34 # Try to cache everything we're likely to need after ejecting.  This
35 # is fragile and simple-minded, but our options are limited.
36 cache_path() {
37     path="$1"
38
39     if [ -d "$path" ]; then
40         find "$path" -type f | xargs cat > /dev/null 2>&1
41     elif [ -f "$path" ]; then
42         if [ -x "$path" ]; then
43             if file "$path" | grep -q 'dynamically linked'; then
44                 for lib in $(ldd "$path" | awk '{ print $3 }'); do
45                     cache_path "$lib"
46                 done
47             fi
48         fi
49         cat "$path" >/dev/null 2>&1
50     fi
51 }
52
53 do_stop ()
54 {
55         # check for netboot
56         if [ ! -z "${NETBOOT}" ] || grep -qs netboot /proc/cmdline || grep -qsi root=/dev/nfs /proc/cmdline  || grep -qsi root=/dev/cifs /proc/cmdline ; then
57                 return 0
58         fi
59
60         for path in $(which halt) $(which reboot) /etc/rc?.d /etc/default; do
61                 cache_path "$path"
62         done
63
64         eject -p -m /live_media >/dev/null 2>&1
65
66         # XXX - i18n
67         echo -n "Please remove the disc and close the tray (if any) then press ENTER: "
68         if [ -x /sbin/usplash_write ]; then
69                 /sbin/usplash_write "TIMEOUT 0"
70                 /sbin/usplash_write "TEXT Please remove the disc, close the tray (if any)"
71                 /sbin/usplash_write "TEXT and press ENTER to continue"
72         fi
73
74         read x < /dev/console
75 }
76
77 case "$1" in
78         start|restart|reload|force-reload|status)
79                 ;;
80         stop)
81                 do_stop
82                 case "$?" in
83                         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
84                         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
85                 esac
86                 ;;
87         *)
88                 echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
89                 exit 3
90                 ;;
91 esac
92