| 1 | #!/bin/sh |
| 2 | |
| 3 | # live-tools(7) - System Support Scripts |
| 4 | # Copyright (C) 2016-2020 The Debian Live team |
| 5 | # Copyright (C) 2006-2015 Daniel Baumann <[email protected]> |
| 6 | # |
| 7 | # This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING. |
| 8 | # This is free software, and you are welcome to redistribute it |
| 9 | # under certain conditions; see COPYING for details. |
| 10 | |
| 11 | set -e |
| 12 | |
| 13 | # Exit if system is not a live system |
| 14 | if ! grep -qs "boot=live" /proc/cmdline || \ |
| 15 | # Exit if system is netboot |
| 16 | grep -qs "netboot" /proc/cmdline || \ |
| 17 | grep -qs "root=/dev/nfs" /proc/cmdline || \ |
| 18 | grep -qs "root=/dev/cifs" /proc/cmdline || \ |
| 19 | # Exit if system is findiso |
| 20 | grep -qs "findiso" /proc/cmdline || \ |
| 21 | # Exit if system is toram |
| 22 | grep -qs "toram" /proc/cmdline || \ |
| 23 | # Exit if user disabled medium eject |
| 24 | grep -qs "cdrom-detect/eject=false" /proc/cmdline || \ |
| 25 | grep -qs "noeject" /proc/cmdline |
| 26 | then |
| 27 | exit 0 |
| 28 | fi |
| 29 | |
| 30 | # Reading configuration files from filesystem and live-medium |
| 31 | for _FILE in /etc/live/tools.conf /etc/live/tools/* \ |
| 32 | /run/live/medium/live/tools.conf /run/live/medium/live/tools/* |
| 33 | do |
| 34 | if [ -e "${_FILE}" ] |
| 35 | then |
| 36 | . "${_FILE}" |
| 37 | fi |
| 38 | done |
| 39 | |
| 40 | # Setting defaults |
| 41 | LIVE_MEDIUM_EJECT_VERBOSE="${LIVE_MEDIUM_EJECT_VERBOSE:-true}" |
| 42 | |
| 43 | # Ejecting live-medium |
| 44 | _DEVICE="$(findmnt -Un -o source /run/live/medium | sed -e 's|^/dev/||')" |
| 45 | |
| 46 | # Systemd version >=253, the mount point for live medium is remounted dynamically when rebooting/halting. |
| 47 | # Mount point is like /run/shutdown/mounts/4fefd9f5c22cea7e |
| 48 | if [ -z "${_DEVICE}" ] |
| 49 | then |
| 50 | live_media_mnt="$(df --output=target | grep -Ew "^/run/shutdown/mounts")" |
| 51 | _DEVICE="$(findmnt -Un -o source $live_media_mnt | sed -e 's|^/dev/||')" |
| 52 | fi |
| 53 | |
| 54 | if [ ! -b "/dev/${_DEVICE}" ] |
| 55 | then |
| 56 | exit 0 |
| 57 | fi |
| 58 | |
| 59 | case "${_DEVICE}" in |
| 60 | sd*) |
| 61 | _DEVICE=$(echo $_DEVICE | sed -e 's/[0-9]*$//') |
| 62 | if readlink "/sys/block/${_DEVICE}" | grep -q usb |
| 63 | then |
| 64 | # ignoring usb mass storage devices |
| 65 | # (they need coldreboot to recover) |
| 66 | exit 0 |
| 67 | fi |
| 68 | ;; |
| 69 | esac |
| 70 | |
| 71 | if [ -x "$(which eject 2> /dev/null)" ] |
| 72 | then |
| 73 | # Give some time for the code afterwards to execute itself before |
| 74 | # we remove the medium used by the root filesystem... |
| 75 | (sleep 1; eject -p -m /dev/${_DEVICE}) >/dev/null 2>&1 & |
| 76 | WAIT_EJECT=1 |
| 77 | fi |
| 78 | |
| 79 | case "${LIVE_MEDIUM_EJECT_VERBOSE}" in |
| 80 | true) |
| 81 | if [ -x /bin/plymouth ] && plymouth --ping |
| 82 | then |
| 83 | plymouth message --text="Please remove the live-medium, close the tray (if any) and press ENTER to continue:" |
| 84 | plymouth watch-keystroke > /dev/null |
| 85 | else |
| 86 | stty sane < /dev/console |
| 87 | |
| 88 | printf "\n\nPlease remove the live-medium, close the tray (if any) and press ENTER to continue:" > /dev/console |
| 89 | |
| 90 | read x < /dev/console |
| 91 | fi |
| 92 | ;; |
| 93 | esac |
| 94 | |
| 95 | if [ -n "$WAIT_EJECT" ]; then |
| 96 | wait |
| 97 | fi |