Using sendsigs.omit to avoid killing / (Closes: #584690).
[debian-live-boot/hramrach.git] / debian / live-boot.init
blobc8c48206d405800888fcf94ad400e0637da675be
1 #!/bin/sh
3 ### BEGIN INIT INFO
4 # Provides: live-boot
5 # Required-Start: $syslog bootmisc
6 # Required-Stop:
7 # Should-Start: $local_fs
8 # Should-Stop: halt reboot
9 # X-Stop-After: umountroot
10 # Default-Start: S
11 # Default-Stop: 0 6
12 # Short-Description: live-boot init script
13 # Description: Resyncs snapshots, evantually caches files in order to
14 # let remove the media.
15 ### END INIT INFO
17 # Authors: Tollef Fog Heen <tfheen@canonical.com>
18 # Marco Amadori <marco.amadori@gmail.com>
20 PATH=/usr/sbin:/usr/bin:/sbin:/bin
21 NAME=live-boot
22 SCRIPTNAME=/etc/init.d/${NAME}
23 DO_SNAPSHOT=/sbin/live-snapshot
25 # Exit if system was not booted by live-boot
26 grep -qs boot=live /proc/cmdline || exit 0
28 # Read configuration variable file if it is present
29 [ -r /etc/live.conf ] && . /etc/live.conf
31 # Load the VERBOSE setting and other rcS variables
32 [ -f /etc/default/rcS ] && . /etc/default/rcS
34 # Define LSB log_* functions.
35 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
36 . /lib/lsb/init-functions
38 # Try to cache everything we're likely to need after ejecting. This
39 # is fragile and simple-minded, but our options are limited.
40 cache_path()
42 path="${1}"
44 if [ -d "${path}" ]
45 then
46 find "${path}" -type f | xargs cat > /dev/null 2>&1
47 elif [ -f "${path}" ]
48 then
49 if [ -x "${path}" ]
50 then
51 if file "${path}" | grep -q 'dynamically linked'
52 then
53 for lib in $(ldd "${path}" | awk '{ print $3 }')
55 cache_path "${lib}"
56 done
60 cat "${path}" >/dev/null 2>&1
64 get_boot_device()
66 # search in /proc/mounts for the device that is mounted at /live/image
67 while read DEVICE MOUNT REST
69 if [ "${MOUNT}" = "/live/image" ]
70 then
71 echo "${DEVICE}"
72 exit 0
74 done < /proc/mounts
77 device_is_USB_flash_drive()
79 # remove leading "/dev/" and all trailing numbers from input
80 DEVICE=$(expr substr ${1} 6 3)
82 # check that device starts with "sd"
83 [ "$(expr substr ${DEVICE} 1 2)" != "sd" ] && return 1
85 # check that the device is an USB device
86 if readlink /sys/block/${DEVICE} | grep -q usb ||
87 readlink /sys/block/${DEVICE}/device | grep -q usb # linux < 2.6.29
88 then
89 return 0
92 return 1
95 do_stop ()
97 if ! grep -qs nopersistent /proc/cmdline && grep -qs persistent /proc/cmdline
98 then
99 if [ ! -z "${ROOTSNAP}" ]
100 then
101 ${DO_SNAPSHOT} --resync-string="${ROOTSNAP}"
104 if [ ! -z "${HOMESNAP}" ]
105 then
106 ${DO_SNAPSHOT} --resync-string="${HOMESNAP}"
110 # check for netboot
111 if [ ! -z "${NETBOOT}" ] || grep -qs netboot /proc/cmdline || grep -qsi root=/dev/nfs /proc/cmdline || grep -qsi root=/dev/cifs /proc/cmdline
112 then
113 return 0
116 # Don't prompt to eject the SD card on Babbage board, where we reuse it
117 # as a quasi-boot-floppy. Technically this uses a bit of ubiquity
118 # (archdetect), but since this is mostly only relevant for
119 # installations, who cares ...
120 if type archdetect >/dev/null 2>&1
121 then
122 subarch="$(archdetect)"
124 case $subarch in
125 arm*/imx51)
126 return 0
128 esac
131 prompt=1
132 if grep -qs noprompt /proc/cmdline
133 then
134 prompt=
137 for path in $(which halt) $(which reboot) /etc/rc?.d /etc/default $(which stty) /bin/plymouth /sbin/usplash_write
139 cache_path "${path}"
140 done
142 for x in $(cat /proc/cmdline)
144 case ${x} in
145 quickreboot)
146 QUICKREBOOT="Yes"
148 esac
149 done
151 if [ -z ${QUICKREBOOT} ]
152 then
154 # Exit if the system was booted from an ISO image rather than a physical CD
155 grep -qs find_iso= /proc/cmdline && return 0
156 # TODO: i18n
157 BOOT_DEVICE="$(get_boot_device)"
159 if device_is_USB_flash_drive ${BOOT_DEVICE}
160 then
161 # do NOT eject USB flash drives!
162 # otherwise rebooting with most USB flash drives
163 # failes because they actually remember the
164 # "ejected" state even after reboot
165 MESSAGE="Please remove the USB flash drive"
166 else
167 # ejecting is a very good idea here
168 MESSAGE="Please remove the disc, close the the tray (if any)"
170 if [ -x /usr/bin/eject ]
171 then
172 eject -p -m /live/image >/dev/null 2>&1
177 [ "$prompt" ] || return 0
179 if [ -x /bin/plymouth ] && plymouth --ping
180 then
181 plymouth message --text="${MESSAGE} and press ENTER to continue:"
182 plymouth watch-keystroke > /dev/null
183 else
184 stty sane < /dev/console
186 printf "\n\n${MESSAGE} and press ENTER to continue:" > /dev/console
188 if [ -x /sbin/usplash_write ]
189 then
190 /sbin/usplash_write "TIMEOUT 86400"
191 /sbin/usplash_write "TEXT-URGENT ${MESSAGE}"
192 /sbin/usplash_write "TEXT-URGENT and press ENTER to continue"
195 read x < /dev/console
200 case "${1}" in
201 restart|reload|force-reload|status)
202 [ "${VERBOSE}" != no ] && log_end_msg 0
204 start)
205 log_begin_msg "${NAME} is configuring sendsigs..."
206 if [ -f /live/image/root.pid ] ; then
207 cat /live/image/root.pid >> /var/run/sendsigs.omit
211 stop)
212 log_begin_msg "${NAME} is resyncing snapshots and caching reboot files..."
213 do_stop
215 case "${?}" in
216 0|1)
217 [ "${VERBOSE}" != no ] && log_end_msg 0
221 [ "${VERBOSE}" != no ] && log_end_msg 1
223 esac
225 mount -o remount,ro /live/cow
229 log_success_msg "Usage: ${SCRIPTNAME} {start|stop|restart|force-reload}" >&2
230 exit 3
232 esac