X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=usr_sbin%2Fgrml2ram;h=a4e119ebd4c358111343c35b5d8cf0908254740f;hb=3b7f948896440f41092f14347b17ce114072c569;hp=dd038d278ab5e9f36e654f65be2fa33267e1ce46;hpb=9fef74081f53d30174118872324fa62d4a8145b5;p=grml-scripts.git diff --git a/usr_sbin/grml2ram b/usr_sbin/grml2ram index dd038d2..a4e119e 100755 --- a/usr_sbin/grml2ram +++ b/usr_sbin/grml2ram @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # Filename: grml2ram # Purpose: copy compressed GRML image to RAM # Authors: (c) Michael Schierl , (c) Michael Prokop @@ -8,7 +8,9 @@ set -e +# shellcheck disable=SC1091 . /etc/grml/lsb-functions +# shellcheck disable=SC1091 . /etc/grml/script-functions check4root || exit 1 @@ -19,7 +21,38 @@ if ! isgrmlcd ; then exit 1 fi -IMAGE=$(ls /live/image/live/*.squashfs 2>/dev/null | head -1) +# initramfs layout since December 2012, backwards compatibility: +[ -d /lib/live/mount/medium ] && export LIVECD_PATH='/lib/live/mount/medium' +# initramfs layout since December 2018: +[ -d /run/live/medium ] && export LIVECD_PATH='/run/live/medium' + +if [ -z "$CMDLINE" ]; then + # if CMDLINE was set from the outside, we're debugging. + # otherwise, take CMDLINE from Kernel and config files. + CMDLINE="$(cat /proc/cmdline)" + [ -d ${LIVECD_PATH}/bootparams/ ] && CMDLINE="$CMDLINE $(cat ${LIVECD_PATH}/bootparams/* | tr '\n' ' ')" +fi + +getbootparam(){ + local line + local ws + ws=' ' + line=" $CMDLINE " + case "$line" in + *[${ws}]"$1="*) + result="${line##*[$ws]$1=}" + result="${result%%[$ws]*}" + echo "$result" + return 0 ;; + *) # no match? + return 1 ;; + esac +} + +MEDIA_PATH="$(getbootparam live-media-path)" +MEDIA_PATH="${MEDIA_PATH:-.}" + +IMAGE=$(find "${LIVECD_PATH}/${MEDIA_PATH}/" -name "*.squashfs" 2>/dev/null | head -1) if ! [ -r "$IMAGE" ] ; then if [ -r /cdrom/GRML/GRML ] ; then IMAGE='/cdrom/GRML/GRML' @@ -37,7 +70,7 @@ case "$*" in -f|--force) ewarn "Forcing copy process for grml-image (${GRMLSIZE}kB) as requested via force option." ; eend 0 ;; *) - if test $RAM -lt $GRMLSIZE ; then + if test "$RAM" -lt "$GRMLSIZE" ; then eerror "Sorry, not enough free RAM (${RAM}kB) available for grml-image (${GRMLSIZE}kB)." ; eend 1 exit 1 fi @@ -49,20 +82,28 @@ rsync -a --progress $IMAGE /tmp/GRML LANGUAGE=C LANG=C LC_ALL=C perl << EOF open LOOP, '