From 8702496bfb0205764569782a9a2ebd11fd80e5e8 Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Thu, 8 Dec 2022 16:27:31 +0100 Subject: bootctl: unlink and cleanup functions The unlink command removes an entry from the ESP including referenced files that are not referenced in other entries. That is useful eg to have multiple entries that use the same kernel with different options. The cleanup command removes all files that are not referenced by any entry. --- src/kernel-install/test-kernel-install.sh | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/kernel-install/test-kernel-install.sh') diff --git a/src/kernel-install/test-kernel-install.sh b/src/kernel-install/test-kernel-install.sh index 2e44063668..f16bb9f50f 100755 --- a/src/kernel-install/test-kernel-install.sh +++ b/src/kernel-install/test-kernel-install.sh @@ -9,6 +9,8 @@ plugin="${2:?}" D="$(mktemp --tmpdir --directory "test-kernel-install.XXXXXXXXXX")" +export _KERNEL_INSTALL_BOOTCTL="$PROJECT_BUILD_ROOT/bootctl" + # shellcheck disable=SC2064 trap "rm -rf '$D'" EXIT INT QUIT PIPE mkdir -p "$D/boot" @@ -31,6 +33,7 @@ EOF export KERNEL_INSTALL_CONF_ROOT="$D/sources" export KERNEL_INSTALL_PLUGINS="$plugin" export BOOT_ROOT="$D/boot" +export BOOT_MNT="$D/boot" export MACHINE_ID='3e0484f3634a418b8e6a39e8828b03e3' "$kernel_install" -v add 1.1.1 "$D/sources/linux" "$D/sources/initrd" @@ -82,3 +85,32 @@ grep -qE '^initrd .*/the-token/1.1.1/initrd' "$entry" grep -qE 'image' "$BOOT_ROOT/the-token/1.1.1/linux" grep -qE 'initrd' "$BOOT_ROOT/the-token/1.1.1/initrd" + +if test -x "$_KERNEL_INSTALL_BOOTCTL"; then + echo "Testing bootctl" + e2="${entry%+*}_2.conf" + cp "$entry" "$e2" + export SYSTEMD_ESP_PATH=/ + + # create file that is not referenced. Check if cleanup removes + # it but leaves the rest alone + :> "$BOOT_ROOT/the-token/1.1.2/initrd" + "$_KERNEL_INSTALL_BOOTCTL" --root="$BOOT_ROOT" cleanup + test ! -e "$BOOT_ROOT/the-token/1.1.2/initrd" + test -e "$BOOT_ROOT/the-token/1.1.2/linux" + test -e "$BOOT_ROOT/the-token/1.1.1/linux" + test -e "$BOOT_ROOT/the-token/1.1.1/initrd" + # now remove duplicated entry and make sure files are left over + "$_KERNEL_INSTALL_BOOTCTL" --root="$BOOT_ROOT" unlink "${e2##*/}" + test -e "$BOOT_ROOT/the-token/1.1.1/linux" + test -e "$BOOT_ROOT/the-token/1.1.1/initrd" + test -e "$entry" + test ! -e "$e2" + # remove last entry referencing those files + entry_id="${entry##*/}" + entry_id="${entry_id%+*}.conf" + "$_KERNEL_INSTALL_BOOTCTL" --root="$BOOT_ROOT" unlink "$entry_id" + test ! -e "$entry" + test ! -e "$BOOT_ROOT/the-token/1.1.1/linux" + test ! -e "$BOOT_ROOT/the-token/1.1.1/initrd" +fi -- cgit v1.2.3