Factoring out medium caching in live-medium-eject to live-medium-cache.
authorDaniel Baumann <mail@daniel-baumann.ch>
Fri, 13 Sep 2013 08:55:16 +0000 (10:55 +0200)
committerDaniel Baumann <mail@daniel-baumann.ch>
Fri, 13 Sep 2013 08:55:16 +0000 (10:55 +0200)
bin/live-media-cache [copied from bin/live-media-eject with 50% similarity]
bin/live-media-eject

similarity index 50%
copy from bin/live-media-eject
copy to bin/live-media-cache
index c688cee..41c84f1 100755 (executable)
@@ -12,18 +12,12 @@ set -e
 
 # Exit if system is not a live system
 if ! grep -qs "boot=live" /proc/cmdline || \
-# Exit if system is netboot
-   grep -qs "netboot" /proc/cmdline || \
-   grep -qs "root=/dev/nfs" /proc/cmdline || \
-   grep -qs "root=/dev/cifs" /proc/cmdline || \
 # Exit if system is toram
    grep -qs "toram" /proc/cmdline
 then
        exit 0
 fi
 
-
-
 # Try to cache everything we're likely to need after ejecting.  This
 # is fragile and simple-minded, but our options are limited.
 cache_path()
@@ -63,93 +57,6 @@ cache_path()
        fi
 }
 
-get_boot_device()
-{
-       # search in /proc/mounts for the device that is mounted at /lib/live/mount/medium
-       while read DEVICE MOUNT REST
-       do
-               case "${MOUNT}" in
-                       /lib/live/mount/medium)
-                               echo "${DEVICE}"
-                               exit 0
-                               ;;
-               esac
-       done < /proc/mounts
-}
-
-device_is_USB_flash_drive()
-{
-       # remove leading "/dev/" and all trailing numbers from input
-       DEVICE=$(echo ${1} | sed -e 's|/dev/||' -e 's|[0-9].*$||')
-
-       # check that device starts with "sd"
-       case "${DEVICE}" in
-               sd*)
-                       ;;
-
-               *)
-                       return 1
-                       ;;
-       esac
-
-       # check that the device is an USB device
-       if readlink /sys/block/${DEVICE} | grep -q usb
-       then
-               return 0
-       fi
-
-       return 1
-}
-
-Eject ()
-{
-       # TODO: i18n
-       BOOT_DEVICE="$(get_boot_device)"
-
-       if device_is_USB_flash_drive ${BOOT_DEVICE}
-       then
-               # do NOT eject USB flash drives!
-               # otherwise rebooting with most USB flash drives
-               # failes because they actually remember the
-               # "ejected" state even after reboot
-               MESSAGE="Please remove the USB flash drive"
-
-               case "${NOPROMPT}" in
-                       usb)
-                               prompt=
-                               ;;
-               esac
-       else
-               # ejecting is a very good idea here
-               MESSAGE="Please remove the disc, close the tray (if any)"
-
-               if [ -x /usr/bin/eject ]
-               then
-                       eject -p -m /lib/live/mount/medium >/dev/null 2>&1
-               fi
-
-               case "${NOPROMPT}" in
-                       cd)
-                               prompt=
-                               ;;
-               esac
-       fi
-
-       [ "$prompt" ] || return 0
-
-       if [ -x /bin/plymouth ] && plymouth --ping
-       then
-               plymouth message --text="${MESSAGE} and press ENTER to continue:"
-               plymouth watch-keystroke > /dev/null
-       else
-               stty sane < /dev/console
-
-               printf "\n\n${MESSAGE} and press ENTER to continue:" > /dev/console
-
-               read x < /dev/console
-       fi
-}
-
 echo "live-tools: caching reboot files..."
 
 prompt=1
@@ -175,13 +82,3 @@ done
 
 # Flush filesystem buffers
 sync
-
-# Check if we need to eject the drive
-if grep -qs "cdrom-detect/eject=false" /proc/cmdline || \
-   grep -qs "noeject" /proc/cmdline || \
-   grep -qs "find_iso" /proc/cmdline
-then
-       return
-else
-       Eject
-fi
index c688cee..20768c0 100755 (executable)
@@ -24,45 +24,6 @@ fi
 
 
 
-# Try to cache everything we're likely to need after ejecting.  This
-# is fragile and simple-minded, but our options are limited.
-cache_path()
-{
-       path="${1}"
-
-       if [ -d "${path}" ]
-       then
-               find "${path}" -type f | xargs cat > /dev/null 2>&1
-       elif [ -f "${path}" ]
-       then
-               if [ -x /usr/bin/file ] && file -L "${path}" | grep -q 'dynamically linked'
-               then
-                       # ldd output can be of three forms:
-                       # 1. linux-vdso.so.1 =>  (0x00007fffe3fb4000)
-                       #    This is a virtual, kernel shared library and we want to skip it
-                       # 2. libc.so.6 => /lib/libc.so.6 (0x00007f5e9dc0c000)
-                       #    We want to cache the third word.
-                       # 3. /lib64/ld-linux-x86-64.so.2 (0x00007f5e9df8b000)
-                       #    We want to cache the first word.
-                       ldd "${path}" | while read line
-                       do
-                               if echo "$line" | grep -qs ' =>  '
-                               then
-                                       continue
-                               elif echo "$line" | grep -qs ' => '
-                               then
-                                       lib=$(echo "${line}" | awk '{ print $3 }')
-                               else
-                                       lib=$(echo "${line}" | awk '{ print $1 }')
-                               fi
-                               cache_path "${lib}"
-                       done
-               fi
-
-               cat "${path}" >/dev/null 2>&1
-       fi
-}
-
 get_boot_device()
 {
        # search in /proc/mounts for the device that is mounted at /lib/live/mount/medium
@@ -150,8 +111,6 @@ Eject ()
        fi
 }
 
-echo "live-tools: caching reboot files..."
-
 prompt=1
 
 case "${NOPROMPT}" in
@@ -160,22 +119,6 @@ case "${NOPROMPT}" in
                ;;
 esac
 
-for path in $(which halt) $(which reboot) /etc/rc?.d /etc/default $(which stty) /bin/plymouth
-do
-       cache_path "${path}"
-done
-
-mount -o remount,ro /lib/live/mount/overlay > /dev/null 2>&1
-
-# Remounting any persistence devices read-only
-for _MOUNT in $(awk '/\/lib\/live\/mount\/persistence/ { print $2 }' /proc/mounts)
-do
-       mount -o remount,ro ${_MOUNT} > /dev/null 2>&1
-done
-
-# Flush filesystem buffers
-sync
-
 # Check if we need to eject the drive
 if grep -qs "cdrom-detect/eject=false" /proc/cmdline || \
    grep -qs "noeject" /proc/cmdline || \