| 1 | #!/bin/shscip-shell filesystem . . `/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 | if [scip-shell system . . `[`. ! -e /usr/sbin/update-initramfs.orig.initramfs-toolsscip-shell filesystem . . `/usr/sbin/update-initramfs.orig.initramfs-tools`. ] |
| 14 | then |
| 15 | echoscip-shell system . . echo. "E: /usr/sbin/update-initramfs.orig.initramfs-tools - command not found" |
| 16 | echoscip-shell system . . echo. "E: On Debian based systems, update-initramfs from initramfs-tools" |
| 17 | echoscip-shell system . . echo. "E: can be installed with:" |
| 18 | echoscip-shell system . . echo. "E: apt-get install initramfs-tools" |
| 19 | |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
| 23 | # system is a live system and not a system in the process of being built by live-build |
| 24 | if [scip-shell system . . `[`. ! -e /.live-buildscip-shell filesystem . . `/.live-build`. ] && grepscip-shell system . . grep. -qs "boot=live" /proc/cmdlinescip-shell filesystem . . `/proc/cmdline`. |
| 25 | then |
| 26 | if grepscip-shell system . . grep. -qs "\/run\/live\/medium" /proc/mountsscip-shell filesystem . . `/proc/mounts`. |
| 27 | then |
| 28 | # live system with live media mounted as /run/live/medium |
| 29 | _DEVICE="$(awkscip-shell system . . awk. '/\/run\/live\/medium/ { print $1 }scip-shell filesystem . . `/\/run\/live\/medium/ { print $1 }`.' /proc/mountsscip-shell filesystem . . `/proc/mounts`.)" |
| 30 | |
| 31 | mountscip-shell system . . mount. -o remount,rw ${_DEVICE} > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || truescip-shell system . . true. |
| 32 | |
| 33 | if touchscip-shell system . . touch. /run/live/medium/.testscip-shell filesystem . . `/run/live/medium/.test`. > /dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 34 | then |
| 35 | _READ_WRITE="true" |
| 36 | |
| 37 | rmscip-shell system . . rm. -f /run/live/medium/.testscip-shell filesystem . . `/run/live/medium/.test`. |
| 38 | else |
| 39 | _READ_WRITE="false" |
| 40 | fi |
| 41 | else |
| 42 | # live system without live media mounted as /run/live/medium |
| 43 | echoscip-shell system . . echo. "I: update-initramfs is disabled (live system is running without media mounted on /run/live/medium)." |
| 44 | |
| 45 | exit 0 |
| 46 | fi |
| 47 | else |
| 48 | # non-live system |
| 49 | /usr/sbin/update-initramfs.orig.initramfs-toolsscip-shell filesystem . . `/usr/sbin/update-initramfs.orig.initramfs-tools`. "${@}" |
| 50 | |
| 51 | exit "${?}" |
| 52 | fi |
| 53 | |
| 54 | case "${_READ_WRITE}" in |
| 55 | true) |
| 56 | # Updating initramfs |
| 57 | /usr/sbin/update-initramfs.orig.initramfs-toolsscip-shell filesystem . . `/usr/sbin/update-initramfs.orig.initramfs-tools`. "${@}" |
| 58 | |
| 59 | if [scip-shell system . . `[`. "$(lsscip-shell system . . ls. /boot/vmlinuz-* | wcscip-shell system . . wc. -l)" -gt 1 ] |
| 60 | then |
| 61 | _NUMBER="1" |
| 62 | |
| 63 | for _VMLINUZ in /boot/vmlinuz-* |
| 64 | do |
| 65 | _VERSION="$(basenamescip-shell system . . basename. ${_VMLINUZ} | sedscip-shell system . . sed. -e 's|vmlinuz-||')" |
| 66 | |
| 67 | cpscip-shell system . . cp. /boot/vmlinuz-${_VERSION} /run/live/medium/live/vmlinuz${_NUMBER}.new |
| 68 | if [scip-shell system . . `[`. -e /boot/initrd.img-${_VERSION} ]; then |
| 69 | cpscip-shell system . . cp. /boot/initrd.img-${_VERSION} /run/live/medium/live/initrd${_NUMBER}.img.new |
| 70 | fi |
| 71 | |
| 72 | _NUMBER="$((${_NUMBER} + 1))" |
| 73 | done |
| 74 | else |
| 75 | _VMLINUZ=$(echoscip-shell system . . echo. /boot/vmlinuz-*) |
| 76 | _VERSION="$(basenamescip-shell system . . basename. ${_VMLINUZ} | sedscip-shell system . . sed. -e 's|vmlinuz-||')" |
| 77 | cpscip-shell system . . cp. $_VMLINUZ /run/live/medium/live/vmlinuz.newscip-shell filesystem . . `/run/live/medium/live/vmlinuz.new`. |
| 78 | if [scip-shell system . . `[`. -e /boot/initrd.img-${_VERSION} ]; then |
| 79 | cpscip-shell system . . cp. /boot/initrd.img-${_VERSION} /run/live/medium/live/initrd.img.newscip-shell filesystem . . `/run/live/medium/live/initrd.img.new`. |
| 80 | fi |
| 81 | |
| 82 | fi |
| 83 | for f in /run/live/medium/live/vmlinuz*.new \ |
| 84 | /run/live/medium/live/initrd*.new; do |
| 85 | if [scip-shell system . . `[`. -e $f ]; then |
| 86 | mvscip-shell system . . mv. $f ${f%.new} |
| 87 | fi |
| 88 | done |
| 89 | ;; |
| 90 | |
| 91 | false) |
| 92 | echoscip-shell system . . echo. "I: update-initramfs is disabled (live system is running on read-only media)." |
| 93 | exit 0 |
| 94 | ;; |
| 95 | esac |