7 # For whatever reason, the initscript that calls us sets a pretty scarse $PATH
8 PATH
="/usr/bin:${PATH}"
13 grep -qs -w -E '(fromiso|isofrom)=' /proc
/cmdline
16 # Returns the boot device's path in a form that can be passed to the
17 # eject command, e.g. /dev/scd0 or /dev/block/NN:MM.
19 if using_fromiso
; then
20 # When booting with e.g. fromiso=/dev/sdx3/tails-XXX.iso, a loop device
21 # is mounted onto /live/image => we cannot get the boot device from there.
22 # This loop device's backing file is seen by the system as
23 # /isofrom/XXX.iso, which is not available presumably because pivotroot
24 # was run => we cannot get the boot device from there either.
25 # Instead, we parse fromiso='s argument the same way live-boot does
26 # in order to extract the device path (/dev/sdx3)
27 for ARGUMENT
in $
(cat /proc
/cmdline
) ; do
30 FROMISO
="${ARGUMENT#*=}"
34 echo $
(dirname "$FROMISO")
36 # Refactorer, beware: the rest of this script depends on the fact that
37 # the path returned in this case is suitable to be passed as an argument
38 # to --path in "udevadm info --query" commands... which is not the case
39 # of paths in the /dev/sdxN form.
40 DEV_NUMBER
="$(udevadm info --device-id-of-file=/live/image)"
41 echo "/dev/block/$DEV_NUMBER"
45 # First clean the screen, then brutally shutdown the machine.
47 /etc
/init.d
/gdm3 stop
2>&1 >/dev
/null || true
48 /etc
/init.d
/kexec-load stop
2>&1 >/dev
/null || true
49 /etc
/init.d
/tails-kexec stop
2>&1 >/dev
/null || true
55 BOOT_DEVICE
=$
(boot_device
)
57 # Assign to QUERY_SELECTOR an option that can be passed as a query selector
58 # to udevadm info --query commands.
59 if using_fromiso
; then
60 DEV_NAME
=$
(basename "$BOOT_DEVICE")
61 QUERY_SELECTOR
="--name $DEV_NAME"
63 QUERY_SELECTOR
="--path $BOOT_DEVICE"
66 DEV_UDEV_PATH
=$
(udevadm info
--query path
$QUERY_SELECTOR)
67 DEV_TYPE_LINE
=$
(udevadm info
--query property
$QUERY_SELECTOR |
grep -w '^ID_TYPE')
68 DEV_TYPE
="${DEV_TYPE_LINE#*=}"
70 # If the world was sane we'd want to *disable* the eject lock, but it turns out
71 # that blocks the block events so udev-watchdog never receives the "change"
72 # event. See [[bugs/sdmem_on_eject_broken_for_CD]].
73 if [ "$DEV_TYPE" = "cd" ]; then
74 eject
-i on
"${BOOT_DEVICE}"
77 # Start udev-watchdog and stop on clean exit.
78 /usr
/local
/sbin
/udev-watchdog
"$DEV_UDEV_PATH" "$DEV_TYPE" && do_stop