5 # Required-Start: $syslog bootmisc
7 # Should-Start: $local_fs
8 # Should-Stop: halt reboot
9 # X-Stop-After: umountroot
12 # Short-Description: live-boot init script
13 # Description: Resyncs snapshots, evantually caches files in order to
14 # let remove the media.
17 # Authors: Tollef Fog Heen <tfheen@canonical.com>
18 # Marco Amadori <marco.amadori@gmail.com>
20 PATH=/usr/sbin:/usr/bin:/sbin:/bin
22 SCRIPTNAME=/etc/init.d/${NAME}
23 DO_SNAPSHOT=/sbin/live-snapshot
24 SNAPSHOT_CONF="/etc/live/boot.d/snapshot.conf"
26 # Exit if system was not booted by live-boot
27 grep -qs boot=live /proc/cmdline || exit 0
29 # Read snapshot configuration variables
30 [ -r ${SNAPSHOT_CONF} ] && . ${SNAPSHOT_CONF}
32 # Load the VERBOSE setting and other rcS variables
33 [ -f /etc/default/rcS ] && . /etc/default/rcS
35 # Define LSB log_* functions.
36 # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
37 . /lib/lsb/init-functions
39 # Try to cache everything we're likely to need after ejecting. This
40 # is fragile and simple-minded, but our options are limited.
47 find "${path}" -type f | xargs cat > /dev/null 2>&1
52 if file -L "${path}" | grep -q 'dynamically linked'
54 for lib in $(ldd "${path}" | awk '{ print $3 }')
61 cat "${path}" >/dev/null 2>&1
67 # search in /proc/mounts for the device that is mounted at /live/image
68 while read DEVICE MOUNT REST
70 if [ "${MOUNT}" = "/live/image" ]
78 device_is_USB_flash_drive()
80 # remove leading "/dev/" and all trailing numbers from input
81 DEVICE=$(expr substr ${1} 6 3)
83 # check that device starts with "sd"
84 [ "$(expr substr ${DEVICE} 1 2)" != "sd" ] && return 1
86 # check that the device is an USB device
87 if readlink /sys/block/${DEVICE} | grep -q usb
97 if ! grep -qs nopersistent /proc/cmdline && grep -qs persistent /proc/cmdline
99 # ROOTSNAP and HOMESNAP are defined in ${SNAPSHOT_CONF} file
100 if [ ! -z "${ROOTSNAP}" ]
102 ${DO_SNAPSHOT} --resync-string="${ROOTSNAP}"
105 if [ ! -z "${HOMESNAP}" ]
107 ${DO_SNAPSHOT} --resync-string="${HOMESNAP}"
112 if [ ! -z "${NETBOOT}" ] || grep -qs netboot /proc/cmdline || grep -qsi root=/dev/nfs /proc/cmdline || grep -qsi root=/dev/cifs /proc/cmdline
118 if grep -qs toram /proc/cmdline
123 # Don't prompt to eject the SD card on Babbage board, where we reuse it
124 # as a quasi-boot-floppy. Technically this uses a bit of ubiquity
125 # (archdetect), but since this is mostly only relevant for
126 # installations, who cares ...
127 if type archdetect >/dev/null 2>&1
129 subarch="$(archdetect)"
139 if [ ${NOPROMPT} = "Yes" ]
144 for path in $(which halt) $(which reboot) /etc/rc?.d /etc/default $(which stty) /bin/plymouth
149 for x in $(cat /proc/cmdline)
158 if [ -z ${QUICKREBOOT} ]
161 # Exit if the system was booted from an ISO image rather than a physical CD
162 grep -qs find_iso= /proc/cmdline && return 0
164 BOOT_DEVICE="$(get_boot_device)"
166 if device_is_USB_flash_drive ${BOOT_DEVICE}
168 # do NOT eject USB flash drives!
169 # otherwise rebooting with most USB flash drives
170 # failes because they actually remember the
171 # "ejected" state even after reboot
172 MESSAGE="Please remove the USB flash drive"
174 if [ ${NOPROMPT} = "usb" ]
180 # ejecting is a very good idea here
181 MESSAGE="Please remove the disc, close the the tray (if any)"
183 if [ -x /usr/bin/eject ]
185 eject -p -m /live/image >/dev/null 2>&1
188 if [ ${NOPROMPT} = "cd" ]
195 [ "$prompt" ] || return 0
197 if [ -x /bin/plymouth ] && plymouth --ping
199 plymouth message --text="${MESSAGE} and press ENTER to continue:"
200 plymouth watch-keystroke > /dev/null
202 stty sane < /dev/console
204 printf "\n\n${MESSAGE} and press ENTER to continue:" > /dev/console
206 read x < /dev/console
212 restart|reload|force-reload|status)
213 [ "${VERBOSE}" != no ] && log_end_msg 0
216 log_begin_msg "${NAME} is configuring sendsigs..."
217 if [ -f /live/root.pid ] ; then
218 cat /live/root.pid >> /var/run/sendsigs.omit
224 log_begin_msg "${NAME} is resyncing snapshots and caching reboot files..."
229 [ "${VERBOSE}" != no ] && log_end_msg 0
233 [ "${VERBOSE}" != no ] && log_end_msg 1
237 mount -o remount,ro /live/cow
241 log_success_msg "Usage: ${SCRIPTNAME} {start|stop|restart|force-reload}" >&2