3 PATH=/usr/sbin:/usr/bin:/sbin:/bin
5 SCRIPTNAME=/etc/init.d/${NAME}
6 DO_SNAPSHOT=/sbin/live-snapshot
7 SNAPSHOT_CONF="/etc/live/boot.d/snapshot.conf"
9 # Exit if system was not booted by live-boot
10 grep -qs boot=live /proc/cmdline || exit 0
12 # Read snapshot configuration variables
13 [ -r ${SNAPSHOT_CONF} ] && . ${SNAPSHOT_CONF}
15 # Load the VERBOSE setting and other rcS variables
16 [ -f /etc/default/rcS ] && . /etc/default/rcS
18 # Define LSB log_* functions.
19 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
20 . /lib/lsb/init-functions
22 # Try to cache everything we're likely to need after ejecting. This
23 # is fragile and simple-minded, but our options are limited.
30 find "${path}" -type f | xargs cat > /dev/null 2>&1
33 if file -L "${path}" | grep -q 'dynamically linked'
35 # ldd output can be of three forms:
36 # 1. linux-vdso.so.1 => (0x00007fffe3fb4000)
37 # This is a virtual, kernel shared library and we want to skip it
38 # 2. libc.so.6 => /lib/libc.so.6 (0x00007f5e9dc0c000)
39 # We want to cache the third word.
40 # 3. /lib64/ld-linux-x86-64.so.2 (0x00007f5e9df8b000)
41 # We want to cache the first word.
42 ldd "${path}" | while read line
44 if echo "$line" | grep -qs ' => '
47 elif echo "$line" | grep -qs ' => '
49 lib=$(echo "${line}" | awk '{ print $3 }')
51 lib=$(echo "${line}" | awk '{ print $1 }')
57 cat "${path}" >/dev/null 2>&1
63 # search in /proc/mounts for the device that is mounted at /live/image
64 while read DEVICE MOUNT REST
66 if [ "${MOUNT}" = "/live/image" ]
74 device_is_USB_flash_drive()
76 # remove leading "/dev/" and all trailing numbers from input
77 DEVICE=$(expr substr ${1} 6 3)
79 # check that device starts with "sd"
80 [ "$(expr substr ${DEVICE} 1 2)" != "sd" ] && return 1
82 # check that the device is an USB device
83 if readlink /sys/block/${DEVICE} | grep -q usb
93 if ! grep -qs nopersistent /proc/cmdline && grep -qs persistent /proc/cmdline
95 # ROOTSNAP and HOMESNAP are defined in ${SNAPSHOT_CONF} file
96 if [ ! -z "${ROOTSNAP}" ]
98 ${DO_SNAPSHOT} --resync-string="${ROOTSNAP}"
101 if [ ! -z "${HOMESNAP}" ]
103 ${DO_SNAPSHOT} --resync-string="${HOMESNAP}"
108 if [ ! -z "${NETBOOT}" ] || grep -qs netboot /proc/cmdline || grep -qsi root=/dev/nfs /proc/cmdline || grep -qsi root=/dev/cifs /proc/cmdline
114 if grep -qs toram /proc/cmdline
119 # Don't prompt to eject the SD card on Babbage board, where we reuse it
120 # as a quasi-boot-floppy. Technically this uses a bit of ubiquity
121 # (archdetect), but since this is mostly only relevant for
122 # installations, who cares ...
123 if type archdetect >/dev/null 2>&1
125 subarch="$(archdetect)"
135 if [ "${NOPROMPT}" = "Yes" ]
140 for path in $(which halt) $(which reboot) /etc/rc?.d /etc/default $(which stty) /bin/plymouth
145 for x in $(cat /proc/cmdline)
154 mount -o remount,ro /live/cow
156 if [ -z ${QUICKREBOOT} ]
159 # Exit if the system was booted from an ISO image rather than a physical CD
160 grep -qs find_iso= /proc/cmdline && return 0
162 BOOT_DEVICE="$(get_boot_device)"
164 if device_is_USB_flash_drive ${BOOT_DEVICE}
166 # do NOT eject USB flash drives!
167 # otherwise rebooting with most USB flash drives
168 # failes because they actually remember the
169 # "ejected" state even after reboot
170 MESSAGE="Please remove the USB flash drive"
172 if [ "${NOPROMPT}" = "usb" ]
178 # ejecting is a very good idea here
179 MESSAGE="Please remove the disc, close the tray (if any)"
181 if [ -x /usr/bin/eject ]
183 eject -p -m /live/image >/dev/null 2>&1
186 if [ "${NOPROMPT}" = "cd" ]
193 [ "$prompt" ] || return 0
195 if [ -x /bin/plymouth ] && plymouth --ping
197 plymouth message --text="${MESSAGE} and press ENTER to continue:"
198 plymouth watch-keystroke > /dev/null
200 stty sane < /dev/console
202 printf "\n\n${MESSAGE} and press ENTER to continue:" > /dev/console
204 read x < /dev/console
210 start|restart|reload|force-reload|status)
211 [ "${VERBOSE}" != no ] && log_end_msg 0 || exit 0
215 log_begin_msg "${NAME} is resyncing snapshots and caching reboot files..."
220 [ "${VERBOSE}" != no ] && log_end_msg 0 || exit 0
224 [ "${VERBOSE}" != no ] && log_end_msg 1 || exit 1
230 log_success_msg "Usage: ${SCRIPTNAME} {start|stop|restart|force-reload}" >&2