]>
Commit | Line | Data |
---|---|---|
f875e6bc ZJS |
1 | #!/usr/bin/env bash |
2 | # SPDX-License-Identifier: LGPL-2.1-or-later | |
dd2ebd1b | 3 | # shellcheck disable=SC2235 |
f875e6bc ZJS |
4 | set -eu |
5 | set -o pipefail | |
6 | ||
7 | kernel_install="${1:?}" | |
8 | plugin="${2:?}" | |
9 | ||
10 | D="$(mktemp --tmpdir --directory "test-kernel-install.XXXXXXXXXX")" | |
11 | ||
8702496b LN |
12 | export _KERNEL_INSTALL_BOOTCTL="$PROJECT_BUILD_ROOT/bootctl" |
13 | ||
f875e6bc ZJS |
14 | # shellcheck disable=SC2064 |
15 | trap "rm -rf '$D'" EXIT INT QUIT PIPE | |
16 | mkdir -p "$D/boot" | |
17 | mkdir -p "$D/efi" | |
18 | mkdir -p "$D/sources" | |
19 | ||
20 | echo 'buzy image' >"$D/sources/linux" | |
21 | echo 'the initrd' >"$D/sources/initrd" | |
22 | echo 'the-token' >"$D/sources/entry-token" | |
23 | echo 'opt1 opt2' >"$D/sources/cmdline" | |
24 | ||
25 | cat >"$D/sources/install.conf" <<EOF | |
26 | layout=bls | |
27 | initrd_generator=none | |
e1b45a75 | 28 | # those are overridden by envvars |
f875e6bc ZJS |
29 | BOOT_ROOT="$D/badboot" |
30 | MACHINE_ID=badbadbadbadbadbad6abadbadbadbad | |
31 | EOF | |
32 | ||
33 | export KERNEL_INSTALL_CONF_ROOT="$D/sources" | |
34 | export KERNEL_INSTALL_PLUGINS="$plugin" | |
35 | export BOOT_ROOT="$D/boot" | |
8702496b | 36 | export BOOT_MNT="$D/boot" |
f875e6bc ZJS |
37 | export MACHINE_ID='3e0484f3634a418b8e6a39e8828b03e3' |
38 | ||
39 | "$kernel_install" -v add 1.1.1 "$D/sources/linux" "$D/sources/initrd" | |
40 | ||
41 | entry="$BOOT_ROOT/loader/entries/the-token-1.1.1.conf" | |
42 | test -f "$entry" | |
43 | grep -qE '^title ' "$entry" | |
44 | grep -qE '^version +1.1.1' "$entry" | |
45 | grep -qE '^options +opt1 opt2' "$entry" | |
46 | grep -qE '^linux .*/the-token/1.1.1/linux' "$entry" | |
47 | grep -qE '^initrd .*/the-token/1.1.1/initrd' "$entry" | |
48 | ||
49 | grep -qE 'image' "$BOOT_ROOT/the-token/1.1.1/linux" | |
50 | grep -qE 'initrd' "$BOOT_ROOT/the-token/1.1.1/initrd" | |
51 | ||
52 | "$kernel_install" inspect | |
53 | ||
54 | "$kernel_install" -v remove 1.1.1 | |
55 | test ! -f "$entry" | |
56 | test ! -f "$BOOT_ROOT/the-token/1.1.1/linux" | |
57 | test ! -f "$BOOT_ROOT/the-token/1.1.1/initrd" | |
58 | ||
59 | # Invoke kernel-install as installkernel | |
60 | ln -s --relative -v "$kernel_install" "$D/sources/installkernel" | |
61 | "$D/sources/installkernel" -v 1.1.2 "$D/sources/linux" System.map /somedirignored | |
62 | ||
63 | entry="$BOOT_ROOT/loader/entries/the-token-1.1.2.conf" | |
64 | test -f "$entry" | |
65 | grep -qE '^title ' "$entry" | |
66 | grep -qE '^version +1.1.2' "$entry" | |
67 | grep -qE '^options +opt1 opt2' "$entry" | |
68 | grep -qE '^linux .*/the-token/1.1.2/linux' "$entry" | |
69 | ( ! grep -qE '^initrd' "$entry" ) | |
70 | ||
71 | grep -qE 'image' "$BOOT_ROOT/the-token/1.1.2/linux" | |
72 | test ! -e "$BOOT_ROOT/the-token/1.1.2/initrd" | |
73 | ||
74 | # Check installation with boot counting | |
75 | echo '56' >"$D/sources/tries" | |
76 | ||
77 | "$kernel_install" -v add 1.1.1 "$D/sources/linux" "$D/sources/initrd" | |
78 | entry="$BOOT_ROOT/loader/entries/the-token-1.1.1+56.conf" | |
79 | test -f "$entry" | |
80 | grep -qE '^title ' "$entry" | |
81 | grep -qE '^version +1.1.1' "$entry" | |
82 | grep -qE '^options +opt1 opt2' "$entry" | |
83 | grep -qE '^linux .*/the-token/1.1.1/linux' "$entry" | |
84 | grep -qE '^initrd .*/the-token/1.1.1/initrd' "$entry" | |
85 | ||
86 | grep -qE 'image' "$BOOT_ROOT/the-token/1.1.1/linux" | |
87 | grep -qE 'initrd' "$BOOT_ROOT/the-token/1.1.1/initrd" | |
8702496b LN |
88 | |
89 | if test -x "$_KERNEL_INSTALL_BOOTCTL"; then | |
90 | echo "Testing bootctl" | |
91 | e2="${entry%+*}_2.conf" | |
92 | cp "$entry" "$e2" | |
93 | export SYSTEMD_ESP_PATH=/ | |
94 | ||
95 | # create file that is not referenced. Check if cleanup removes | |
96 | # it but leaves the rest alone | |
97 | :> "$BOOT_ROOT/the-token/1.1.2/initrd" | |
98 | "$_KERNEL_INSTALL_BOOTCTL" --root="$BOOT_ROOT" cleanup | |
99 | test ! -e "$BOOT_ROOT/the-token/1.1.2/initrd" | |
100 | test -e "$BOOT_ROOT/the-token/1.1.2/linux" | |
101 | test -e "$BOOT_ROOT/the-token/1.1.1/linux" | |
102 | test -e "$BOOT_ROOT/the-token/1.1.1/initrd" | |
103 | # now remove duplicated entry and make sure files are left over | |
104 | "$_KERNEL_INSTALL_BOOTCTL" --root="$BOOT_ROOT" unlink "${e2##*/}" | |
105 | test -e "$BOOT_ROOT/the-token/1.1.1/linux" | |
106 | test -e "$BOOT_ROOT/the-token/1.1.1/initrd" | |
107 | test -e "$entry" | |
108 | test ! -e "$e2" | |
109 | # remove last entry referencing those files | |
110 | entry_id="${entry##*/}" | |
111 | entry_id="${entry_id%+*}.conf" | |
112 | "$_KERNEL_INSTALL_BOOTCTL" --root="$BOOT_ROOT" unlink "$entry_id" | |
113 | test ! -e "$entry" | |
114 | test ! -e "$BOOT_ROOT/the-token/1.1.1/linux" | |
115 | test ! -e "$BOOT_ROOT/the-token/1.1.1/initrd" | |
116 | fi |