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