-#!/bin/sh
+#!/bin/bash
# Filename: grml2ram
# Purpose: copy compressed GRML image to RAM
# Authors: (c) Michael Schierl <schierlm-public@gmx.de>, (c) Michael Prokop <mika@grml.org>
set -e
+# shellcheck disable=SC1091
. /etc/grml/lsb-functions
+# shellcheck disable=SC1091
. /etc/grml/script-functions
check4root || exit 1
exit 1
fi
+# 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 /cdrom/bootparams/ ] && CMDLINE="$CMDLINE $(cat /cdrom/bootparams/* | tr '\n' ' ')"
- [ -d /live/image/bootparams/ ] && CMDLINE="$CMDLINE $(cat /live/image/bootparams/* | tr '\n' ' ')"
+ [ -d ${LIVECD_PATH}/bootparams/ ] && CMDLINE="$CMDLINE $(cat ${LIVECD_PATH}/bootparams/* | tr '\n' ' ')"
fi
getbootparam(){
MEDIA_PATH="$(getbootparam live-media-path)"
MEDIA_PATH="${MEDIA_PATH:-.}"
-IMAGE=$(find /live/image/${MEDIA_PATH}/ -name *.squashfs 2>/dev/null | head -1)
+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'
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
EOF
# identify cd-rom:
-GRMLDEV=$(awk '{if ($2 ~ /^\/live\/image$/ ) print $1}' /etc/mtab)
+GRMLDEV=$(awk '{if ($2 ~ /^\/lib\/live\/mount\/medium$/ ) print $1}' /etc/mtab)
+if [ -z "$GRMLDEV" ]; then
+ GRMLDEV=$(awk '{if ($2 ~ /^\/live\/image$/ ) print $1}' /etc/mtab)
+fi
if [ -z "$GRMLDEV" ]; then
GRMLDEV=$(awk '{if ($2 ~ /^\/cdrom$/ ) print $1}' /etc/mtab)
-fi
+fi
[ -n "$GRMLDEV" ] || GRMLDEV='/dev/cdrom'
einfo "Unmounting cdrom"
-[ -d /live/image ] && umount /live/image || umount /cdrom
+if [ -d $LIVECD_PATH ] ;
+then
+ umount $LIVECD_PATH
+else
+ umount /cdrom
+fi
eend $?
einfo "Now you can eject your grml-cd (e.g. run 'eject $GRMLDEV')." ; eend 0