diff options
Diffstat (limited to '')
-rwxr-xr-x | modules.d/90dmsquash-live-autooverlay/create-overlay.sh | 44 | ||||
-rwxr-xr-x | modules.d/90dmsquash-live/apply-live-updates.sh | 4 | ||||
-rwxr-xr-x | modules.d/90dmsquash-live/dmsquash-live-root.sh | 60 | ||||
-rwxr-xr-x | modules.d/90dmsquash-live/module-setup.sh | 2 |
4 files changed, 48 insertions, 62 deletions
diff --git a/modules.d/90dmsquash-live-autooverlay/create-overlay.sh b/modules.d/90dmsquash-live-autooverlay/create-overlay.sh index 10e8ea5..05a8c35 100755 --- a/modules.d/90dmsquash-live-autooverlay/create-overlay.sh +++ b/modules.d/90dmsquash-live-autooverlay/create-overlay.sh @@ -14,14 +14,12 @@ gatherData() { info "Skipping overlay creation: kernel command line parameter 'rd.live.overlay' is not set" exit 0 fi - # shellcheck disable=SC2086 - if ! str_starts ${overlay} LABEL=; then + if ! str_starts "${overlay}" LABEL=; then die "Overlay creation failed: the partition must be set by LABEL in the 'rd.live.overlay' kernel parameter" fi overlayLabel=${overlay#LABEL=} - # shellcheck disable=SC2086 - if [ -b /dev/disk/by-label/${overlayLabel} ]; then + if [ -b "/dev/disk/by-label/${overlayLabel}" ]; then info "Skipping overlay creation: overlay already exists" exit 0 fi @@ -41,32 +39,24 @@ gatherData() { # The kernel command line's 'root=' parameter was parsed into the $root variable by the dmsquash-live module. # $root contains the path to a symlink within /dev/disk/by-label, which points to a partition. # This script needs that partition's parent block device. - # shellcheck disable=SC2046 - # shellcheck disable=SC2086 - rootDeviceAbsolutePath=$(readlink -f ${rootDevice}) - rootDeviceSysfsPath=/sys/class/block/${rootDeviceAbsolutePath##*/} + rootDeviceAbsolutePath=$(readlink -f "${rootDevice}") + rootDeviceSysfsPath="/sys/class/block/${rootDeviceAbsolutePath##*/}" if [ -f "${rootDeviceSysfsPath}/partition" ]; then - # shellcheck disable=SC2086 - read -r partition < ${rootDeviceSysfsPath}/partition + read -r partition < "${rootDeviceSysfsPath}/partition" else partition=0 fi - # shellcheck disable=SC2086 - read -r readonly < ${rootDeviceSysfsPath}/ro - # shellcheck disable=SC2086 + read -r readonly < "${rootDeviceSysfsPath}/ro" if [ "$partition" != "1" ] || [ "$readonly" != "0" ]; then info "Skipping overlay creation: unpartitioned or read-only media detected" exit 0 fi - # shellcheck disable=SC2046 - # shellcheck disable=SC2086 - fullDriveSysfsPath=$(readlink -f ${rootDeviceSysfsPath}/..) - blockDevice=/dev/${fullDriveSysfsPath##*/} + fullDriveSysfsPath=$(readlink -f "${rootDeviceSysfsPath}/..") + blockDevice="/dev/${fullDriveSysfsPath##*/}" currentPartitionCount=$(grep --count -E "${blockDevice#/dev/}[0-9]+" /proc/partitions) - # shellcheck disable=SC2086 - freeSpaceStart=$(parted --script ${blockDevice} unit % print free \ - | awk -v x=${currentPartitionCount} '$1 == x {getline; print $1}') + freeSpaceStart=$(parted --script "${blockDevice}" unit % print free \ + | awk -v "x=${currentPartitionCount}" '$1 == x {getline; print $1}') if [ -z "$freeSpaceStart" ]; then info "Skipping overlay creation: there is no free space after the last partition" exit 0 @@ -87,22 +77,18 @@ gatherData() { } createPartition() { - # shellcheck disable=SC2086 - parted --script --align optimal ${blockDevice} mkpart primary ${partitionStart}% 100% + parted --script --align optimal "${blockDevice}" mkpart primary ${partitionStart}% 100% } createFilesystem() { - # shellcheck disable=SC2086 - mkfs.${filesystem} -L ${overlayLabel} ${overlayPartition} + "mkfs.${filesystem}" -L "${overlayLabel}" "${overlayPartition}" baseDir=/run/initramfs/create-overlayfs mkdir -p ${baseDir} - # shellcheck disable=SC2086 - mount -t ${filesystem} ${overlayPartition} ${baseDir} + mount -t "${filesystem}" "${overlayPartition}" ${baseDir} - mkdir -p ${baseDir}/${live_dir}/ovlwork - # shellcheck disable=SC2086 - mkdir ${baseDir}/${live_dir}/overlay-${label}-${uuid} + mkdir -p "${baseDir}/${live_dir}/ovlwork" + mkdir "${baseDir}/${live_dir}/overlay-${label}-${uuid}" umount ${baseDir} rm -r ${baseDir} diff --git a/modules.d/90dmsquash-live/apply-live-updates.sh b/modules.d/90dmsquash-live/apply-live-updates.sh index a5a5a39..be3b2c2 100755 --- a/modules.d/90dmsquash-live/apply-live-updates.sh +++ b/modules.d/90dmsquash-live/apply-live-updates.sh @@ -1,6 +1,6 @@ #!/bin/sh -if [ -h /dev/root ] && [ -d /run/initramfs/live/updates -o -d /updates ]; then +if [ -h /dev/root ] && [ -d /run/initramfs/live/updates ] || [ -d /updates ]; then info "Applying updates to live image..." mount -o bind /run "$NEWROOT"/run # avoid overwriting symlinks (e.g. /lib -> /usr/lib) with directories @@ -16,7 +16,7 @@ if [ -h /dev/root ] && [ -d /run/initramfs/live/updates -o -d /updates ]; then fi # release resources on iso-scan boots with rd.live.ram if [ -d /run/initramfs/isoscan ] \ - && [ -f /run/initramfs/squashed.img -o -f /run/initramfs/rootfs.img ]; then + && [ -f /run/initramfs/squashed.img ] || [ -f /run/initramfs/rootfs.img ]; then umount --detach-loop /run/initramfs/live umount /run/initramfs/isoscan fi diff --git a/modules.d/90dmsquash-live/dmsquash-live-root.sh b/modules.d/90dmsquash-live/dmsquash-live-root.sh index 4518852..e4a3f00 100755 --- a/modules.d/90dmsquash-live/dmsquash-live-root.sh +++ b/modules.d/90dmsquash-live/dmsquash-live-root.sh @@ -67,7 +67,7 @@ if [ ! -f "$livedev" ]; then check_dev=$(get_check_dev "$livedev") # CD/DVD media check [ -b "$check_dev" ] && fs=$(det_fs "$check_dev") - if [ "$fs" = "iso9660" -o "$fs" = "udf" ]; then + if [ "$fs" = "iso9660" ] || [ "$fs" = "udf" ]; then check="yes" fi getarg rd.live.check -d check || check="" @@ -97,7 +97,6 @@ det_img_fs() { blkid -s TYPE -u noraid -o value "$1" } -load_fstype squashfs CMDLINE=$(getcmdline) for arg in $CMDLINE; do case $arg in @@ -112,14 +111,15 @@ if [ -f "$livedev" ]; then # check filesystem type and handle accordingly fstype=$(det_img_fs "$livedev") case $fstype in - squashfs) SQUASHED=$livedev ;; - auto) die "cannot mount live image (unknown filesystem type)" ;; + squashfs | erofs) SQUASHED=$livedev ;; + auto) die "cannot mount live image (unknown filesystem type $fstype)" ;; *) FSIMG=$livedev ;; esac load_fstype "$fstype" else livedev_fstype=$(det_fs "$livedev") - if [ "$livedev_fstype" = "squashfs" ]; then + load_fstype "$livedev_fstype" + if [ "$livedev_fstype" = "squashfs" ] || [ "$livedev_fstype" = "erofs" ]; then # no mount needed - we've already got the LiveOS image in $livedev SQUASHED=$livedev elif [ "$livedev_fstype" != "ntfs" ]; then @@ -148,7 +148,7 @@ do_live_overlay() { pathspec=${overlay##*:} fi - if [ -z "$pathspec" -o "$pathspec" = "auto" ]; then + if [ -z "$pathspec" ] || [ "$pathspec" = "auto" ]; then pathspec="/${live_dir}/overlay-$l-$u" elif ! str_starts "$pathspec" "/"; then pathspec=/"${pathspec}" @@ -156,7 +156,7 @@ do_live_overlay() { devspec=${overlay%%:*} # need to know where to look for the overlay - if [ -z "$setup" -a -n "$devspec" -a -n "$pathspec" -a -n "$overlay" ]; then + if [ -z "$setup" ] && [ -n "$devspec" ] && [ -n "$pathspec" ] && [ -n "$overlay" ]; then mkdir -m 0755 -p /run/initramfs/overlayfs if ismounted "$devspec"; then devmnt=$(findmnt -e -v -n -o 'TARGET' --source "$devspec") @@ -166,8 +166,8 @@ do_live_overlay() { else mount -n -t auto "$devspec" /run/initramfs/overlayfs || : fi - if [ -f /run/initramfs/overlayfs$pathspec -a -w /run/initramfs/overlayfs$pathspec ]; then - OVERLAY_LOOPDEV=$(losetup -f --show ${readonly_overlay:+-r} /run/initramfs/overlayfs$pathspec) + if [ -f "/run/initramfs/overlayfs$pathspec" ] && [ -w "/run/initramfs/overlayfs$pathspec" ]; then + OVERLAY_LOOPDEV=$(losetup -f --show ${readonly_overlay:+-r} "/run/initramfs/overlayfs$pathspec") over=$OVERLAY_LOOPDEV umount -l /run/initramfs/overlayfs || : oltype=$(det_img_fs "$OVERLAY_LOOPDEV") @@ -194,10 +194,10 @@ do_live_overlay() { setup="yes" fi fi - elif [ -d /run/initramfs/overlayfs$pathspec ] \ - && [ -d /run/initramfs/overlayfs$pathspec/../ovlwork ]; then - ln -s /run/initramfs/overlayfs$pathspec /run/overlayfs${readonly_overlay:+-r} - ln -s /run/initramfs/overlayfs$pathspec/../ovlwork /run/ovlwork${readonly_overlay:+-r} + elif [ -d "/run/initramfs/overlayfs$pathspec" ] \ + && [ -d "/run/initramfs/overlayfs$pathspec/../ovlwork" ]; then + ln -s "/run/initramfs/overlayfs$pathspec" /run/overlayfs${readonly_overlay:+-r} + ln -s "/run/initramfs/overlayfs$pathspec/../ovlwork" /run/ovlwork${readonly_overlay:+-r} if [ -z "$overlayfs" ] && [ -n "$DRACUT_SYSTEMD" ]; then reloadsysrootmountunit=":>/xor_overlayfs;" fi @@ -218,10 +218,10 @@ do_live_overlay() { fi fi - if [ -z "$setup" -o -n "$readonly_overlay" ]; then + if [ -z "$setup" ] || [ -n "$readonly_overlay" ]; then if [ -n "$setup" ]; then warn "Using temporary overlay." - elif [ -n "$devspec" -a -n "$pathspec" ]; then + elif [ -n "$devspec" ] && [ -n "$pathspec" ]; then [ -z "$m" ] \ && m=' Unable to find a persistent overlay; using a temporary one.' m="$m"' @@ -265,7 +265,7 @@ do_live_overlay() { fi else dd if=/dev/null of=/overlay bs=1024 count=1 seek=$((overlay_size * 1024)) 2> /dev/null - if [ -n "$setup" -a -n "$readonly_overlay" ]; then + if [ -n "$setup" ] && [ -n "$readonly_overlay" ]; then RO_OVERLAY_LOOPDEV=$(losetup -f --show /overlay) over=$RO_OVERLAY_LOOPDEV else @@ -319,24 +319,24 @@ do_live_overlay() { # end do_live_overlay() # we might have an embedded fs image on squashfs (compressed live) -if [ -e /run/initramfs/live/${live_dir}/${squash_image} ]; then +if [ -e "/run/initramfs/live/${live_dir}/${squash_image}" ]; then SQUASHED="/run/initramfs/live/${live_dir}/${squash_image}" fi if [ -e "$SQUASHED" ]; then if [ -n "$live_ram" ]; then - imgsize=$(($(stat -c %s -- $SQUASHED) / (1024 * 1024))) + imgsize=$(($(stat -c %s -- "$SQUASHED") / (1024 * 1024))) check_live_ram $imgsize echo 'Copying live image to RAM...' > /dev/kmsg echo ' (this may take a minute)' > /dev/kmsg - dd if=$SQUASHED of=/run/initramfs/squashed.img bs=512 2> /dev/null + dd "if=$SQUASHED" of=/run/initramfs/squashed.img bs=512 2> /dev/null echo 'Done copying live image to RAM.' > /dev/kmsg SQUASHED="/run/initramfs/squashed.img" fi SQUASHED_LOOPDEV=$(losetup -f) - losetup -r "$SQUASHED_LOOPDEV" $SQUASHED + losetup -r "$SQUASHED_LOOPDEV" "$SQUASHED" mkdir -m 0755 -p /run/initramfs/squashfs - mount -n -t squashfs -o ro "$SQUASHED_LOOPDEV" /run/initramfs/squashfs + mount -n -o ro "$SQUASHED_LOOPDEV" /run/initramfs/squashfs if [ -d /run/initramfs/squashfs/LiveOS ]; then if [ -f /run/initramfs/squashfs/LiveOS/rootfs.img ]; then @@ -356,15 +356,15 @@ if [ -e "$SQUASHED" ]; then fi else # we might have an embedded fs image to use as rootfs (uncompressed live) - if [ -e /run/initramfs/live/${live_dir}/rootfs.img ]; then + if [ -e "/run/initramfs/live/${live_dir}/rootfs.img" ]; then FSIMG="/run/initramfs/live/${live_dir}/rootfs.img" - elif [ -e /run/initramfs/live/${live_dir}/ext3fs.img ]; then + elif [ -e "/run/initramfs/live/${live_dir}/ext3fs.img" ]; then FSIMG="/run/initramfs/live/${live_dir}/ext3fs.img" fi if [ -n "$live_ram" ]; then echo 'Copying live image to RAM...' > /dev/kmsg echo ' (this may take a minute or so)' > /dev/kmsg - dd if=$FSIMG of=/run/initramfs/rootfs.img bs=512 2> /dev/null + dd "if=$FSIMG" of=/run/initramfs/rootfs.img bs=512 2> /dev/null echo 'Done copying live image to RAM.' > /dev/kmsg FSIMG='/run/initramfs/rootfs.img' fi @@ -376,17 +376,17 @@ if [ -n "$FSIMG" ]; then echo "Unpacking live filesystem (may take some time)" > /dev/kmsg mkdir -m 0755 -p /run/initramfs/fsimg/ if [ -n "$SQUASHED" ]; then - cp -v $FSIMG /run/initramfs/fsimg/rootfs.img + cp -v "$FSIMG" /run/initramfs/fsimg/rootfs.img else - unpack_archive $FSIMG /run/initramfs/fsimg/ + unpack_archive "$FSIMG" /run/initramfs/fsimg/ fi FSIMG=/run/initramfs/fsimg/rootfs.img fi # For writable DM images... readonly_base=1 - if [ -z "$SQUASHED" -a -n "$live_ram" -a -z "$overlayfs" ] \ + if [ -z "$SQUASHED" ] && [ -n "$live_ram" ] && [ -z "$overlayfs" ] \ || [ -n "$writable_fsimg" ] \ - || [ "$overlay" = none -o "$overlay" = None -o "$overlay" = NONE ]; then + || [ "$overlay" = none ] || [ "$overlay" = None ] || [ "$overlay" = NONE ]; then if [ -z "$readonly_overlay" ]; then unset readonly_base setup=rw @@ -397,7 +397,7 @@ if [ -n "$FSIMG" ]; then if [ "$FSIMG" = "$SQUASHED" ]; then BASE_LOOPDEV=$SQUASHED_LOOPDEV else - BASE_LOOPDEV=$(losetup -f --show ${readonly_base:+-r} $FSIMG) + BASE_LOOPDEV=$(losetup -f --show ${readonly_base:+-r} "$FSIMG") sz=$(blockdev --getsz "$BASE_LOOPDEV") fi if [ "$setup" = rw ]; then @@ -422,7 +422,7 @@ fi if [ -n "$overlayfs" ]; then if [ -n "$FSIMG" ]; then mkdir -m 0755 -p /run/rootfsbase - mount -r $FSIMG /run/rootfsbase + mount -r "$FSIMG" /run/rootfsbase else ln -sf /run/initramfs/live /run/rootfsbase fi diff --git a/modules.d/90dmsquash-live/module-setup.sh b/modules.d/90dmsquash-live/module-setup.sh index b905e3d..99d2114 100755 --- a/modules.d/90dmsquash-live/module-setup.sh +++ b/modules.d/90dmsquash-live/module-setup.sh @@ -17,7 +17,7 @@ depends() { # called by dracut installkernel() { - instmods squashfs loop iso9660 + instmods squashfs loop iso9660 erofs } # called by dracut |