#!/usr/bin/env bash # SPDX-License-Identifier: LGPL-2.1-or-later # shellcheck disable=SC2235 set -eux set -o pipefail export SYSTEMD_LOG_LEVEL=debug kernel_install="${1:?}" loaderentry_install="${2:?}" uki_copy_install="${3:?}" ukify="${4:-}" ukify_install="${5:-}" boot_stub="${6:-}" if [[ -d "${PROJECT_BUILD_ROOT:-}" ]]; then bootctl="${PROJECT_BUILD_ROOT}/bootctl" else bootctl= fi D="$(mktemp --tmpdir --directory "test-kernel-install.XXXXXXXXXX")" # shellcheck disable=SC2064 trap "rm -rf '$D'" EXIT INT QUIT PIPE mkdir -p "$D/boot" mkdir -p "$D/efi" mkdir -p "$D/sources" echo 'buzy image' >"$D/sources/linux" echo 'the initrd' >"$D/sources/initrd" echo 'the-token' >"$D/sources/entry-token" echo 'opt1 opt2' >"$D/sources/cmdline" cat >"$D/sources/install.conf" <"$D/sources/tries" "$kernel_install" -v add 1.1.1 "$D/sources/linux" "$D/sources/initrd" entry="$BOOT_ROOT/loader/entries/the-token-1.1.1+56.conf" test -f "$entry" grep -qE '^title ' "$entry" grep -qE '^version +1.1.1' "$entry" grep -qE '^options +opt1 opt2' "$entry" grep -qE '^linux .*/the-token/1.1.1/linux' "$entry" 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" # Install UKI if [ -f "$ukify" ]; then cat >>"$D/sources/install.conf" < "$BOOT_ROOT/the-token/1.1.2/initrd" "$bootctl" --root="$D" 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 "$bootctl" --root="$D" 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" "$bootctl" --root="$D" 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 ########################################### # tests for --make-entry-directory= ########################################### # disable all dropins cat >"$D/00-skip.install" <"$D/sources/install.conf" < layout is other. "$kernel_install" -v add 1.1.1 "$D/sources/linux" "$D/sources/initrd" test ! -e "$BOOT_ROOT/the-token/1.1.1" "$kernel_install" -v remove 1.1.1 test ! -e "$BOOT_ROOT/the-token/1.1.1" # 1.2 token directory exists -> layout is BLS mkdir -p "$BOOT_ROOT/the-token" "$kernel_install" -v add 1.1.1 "$D/sources/linux" "$D/sources/initrd" test -d "$BOOT_ROOT/the-token/1.1.1" "$kernel_install" -v remove 1.1.1 test ! -e "$BOOT_ROOT/the-token/1.1.1" rmdir "$BOOT_ROOT/the-token" # 2. --make-entry-directory=yes # 2.1 token directory does not exist -> layout is other. "$kernel_install" -v --make-entry-directory=yes add 1.1.1 "$D/sources/linux" "$D/sources/initrd" test -d "$BOOT_ROOT/the-token/1.1.1" "$kernel_install" -v --make-entry-directory=yes remove 1.1.1 test ! -e "$BOOT_ROOT/the-token/1.1.1" test -d "$BOOT_ROOT/the-token" # 2.2 token directory exists -> layout is BLS mkdir -p "$BOOT_ROOT/the-token" "$kernel_install" -v --make-entry-directory=yes add 1.1.1 "$D/sources/linux" "$D/sources/initrd" test -d "$BOOT_ROOT/the-token/1.1.1" "$kernel_install" -v --make-entry-directory=yes remove 1.1.1 test ! -e "$BOOT_ROOT/the-token/1.1.1" test -d "$BOOT_ROOT/the-token" rmdir "$BOOT_ROOT/the-token" # 3. --make-entry-directory=no # 3.1 token directory does not exist -> layout is other. "$kernel_install" -v --make-entry-directory=no add 1.1.1 "$D/sources/linux" "$D/sources/initrd" test ! -e "$BOOT_ROOT/the-token/1.1.1" "$kernel_install" -v --make-entry-directory=no remove 1.1.1 test ! -e "$BOOT_ROOT/the-token/1.1.1" # 3.2 token directory exists -> layout is BLS mkdir -p "$BOOT_ROOT/the-token" "$kernel_install" -v --make-entry-directory=no add 1.1.1 "$D/sources/linux" "$D/sources/initrd" test ! -e "$BOOT_ROOT/the-token/1.1.1" "$kernel_install" -v --make-entry-directory=no remove 1.1.1 test ! -e "$BOOT_ROOT/the-token/1.1.1" test -d "$BOOT_ROOT/the-token" rmdir "$BOOT_ROOT/the-token" ########################################### # tests for --entry-token= ########################################### "$kernel_install" -v --make-entry-directory=yes --entry-token=machine-id add 1.1.1 "$D/sources/linux" "$D/sources/initrd" test -d "$BOOT_ROOT/$MACHINE_ID/1.1.1" "$kernel_install" -v --make-entry-directory=yes --entry-token=machine-id remove 1.1.1 test ! -e "$BOOT_ROOT/$MACHINE_ID/1.1.1" test -d "$BOOT_ROOT/$MACHINE_ID" rmdir "$BOOT_ROOT/$MACHINE_ID" "$kernel_install" -v --make-entry-directory=yes --entry-token=literal:hoge add 1.1.1 "$D/sources/linux" "$D/sources/initrd" test -d "$BOOT_ROOT/hoge/1.1.1" "$kernel_install" -v --make-entry-directory=yes --entry-token=literal:hoge remove 1.1.1 test ! -e "$BOOT_ROOT/hoge/1.1.1" test -d "$BOOT_ROOT/hoge" rmdir "$BOOT_ROOT/hoge"