From 6d1479ed5ce3dd725b76f2f613ec4bb6c128ef9c Mon Sep 17 00:00:00 2001 From: nl6720 Date: Tue, 14 Dec 2021 17:57:18 +0200 Subject: hooks/archiso: merge _mnt_sfs and _mnt_erofs into one funtion _mnt_fs Now that EROFS is detected by util-linux, the actions to mount a squashfs or erofs image are basically the same. The _mnt_sfs and _mnt_erofs functions can be merged into one: _mnt_fs. If neither airootfs.sfs nor airootfs.erofs are found, error out to interactive shell. --- hooks/archiso | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) (limited to 'hooks') diff --git a/hooks/archiso b/hooks/archiso index 7e40077..98268a3 100644 --- a/hooks/archiso +++ b/hooks/archiso @@ -55,16 +55,16 @@ _mnt_overlayfs() { } # args: /path/to/image_file, mountpoint -_mnt_sfs() { +_mnt_fs() { local img="${1}" local mnt="${2}" local img_fullname="${img##*/}" - local sfs_dev + local img_loopdev # shellcheck disable=SC2154 # defined via initcpio's parse_cmdline() if [ "${copytoram}" = "y" ]; then - msg -n ":: Copying squashfs image to RAM..." + msg -n ":: Copying rootfs image to RAM..." # in case we have pv use it to display copy progress feedback otherwise # fallback to using plain cp @@ -85,30 +85,8 @@ _mnt_sfs() { img="/run/archiso/copytoram/${img_fullname}" msg "done." fi - sfs_dev="$(losetup --find --show --read-only -- "${img}")" - _mnt_dev "${sfs_dev}" "${mnt}" "-r" "defaults" -} - -# args: /path/to/image_file, mountpoint -_mnt_erofs() { - local img="${1}" - local mnt="${2}" - local img_fullname="${img##*/}" - local erofs_dev - - # shellcheck disable=SC2154 - # defined via initcpio's parse_cmdline() - if [ "${copytoram}" = "y" ]; then - msg -n ":: Copying EROFS image to RAM..." - if ! cp -- "${img}" "/run/archiso/copytoram/${img_fullname}"; then - echo "ERROR: while copy '${img}' to '/run/archiso/copytoram/${img_fullname}'" - launch_interactive_shell - fi - img="/run/archiso/copytoram/${img_fullname}" - msg "done." - fi - erofs_dev="$(losetup --find --show --read-only -- "${img}")" - _mnt_dev "${erofs_dev}" "${mnt}" "-r" "defaults" + img_loopdev="$(losetup --find --show --read-only -- "${img}")" + _mnt_dev "${img_loopdev}" "${mnt}" "-r" "defaults" } # args: device, mountpoint, flags, opts @@ -191,7 +169,7 @@ run_hook() { # args: /path/to/newroot archiso_mount_handler() { local newroot="${1}" - local sigfile + local sigfile fs_img if ! mountpoint -q "/run/archiso/bootmnt"; then _mnt_dev "${archisodevice}" "/run/archiso/bootmnt" "-r" "defaults" @@ -257,10 +235,14 @@ archiso_mount_handler() { chmod 0700 "/run/archiso/cowspace/${cow_directory}" if [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs" ]; then - _mnt_sfs "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs" "/run/archiso/airootfs" + fs_img="/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.sfs" elif [ -f "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.erofs" ]; then - _mnt_erofs "/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.erofs" "/run/archiso/airootfs" + fs_img="/run/archiso/bootmnt/${archisobasedir}/${arch}/airootfs.erofs" + else + echo "ERROR: no root file system image found" + launch_interactive_shell fi + _mnt_fs "${fs_img}" "/run/archiso/airootfs" if [ -f "/run/archiso/airootfs/airootfs.img" ]; then _mnt_dmsnapshot "/run/archiso/airootfs/airootfs.img" "${newroot}" "/" else -- cgit v1.2.3-70-g09d2