]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/kernel-install/test-kernel-install.sh
Merge pull request #25168 from valentindavid/valentindavid/umount-move-recursive...
[thirdparty/systemd.git] / src / kernel-install / test-kernel-install.sh
CommitLineData
f875e6bc
ZJS
1#!/usr/bin/env bash
2# SPDX-License-Identifier: LGPL-2.1-or-later
dd2ebd1b 3# shellcheck disable=SC2235
f875e6bc
ZJS
4set -eu
5set -o pipefail
6
7kernel_install="${1:?}"
8plugin="${2:?}"
9
10D="$(mktemp --tmpdir --directory "test-kernel-install.XXXXXXXXXX")"
11
8702496b
LN
12export _KERNEL_INSTALL_BOOTCTL="$PROJECT_BUILD_ROOT/bootctl"
13
f875e6bc
ZJS
14# shellcheck disable=SC2064
15trap "rm -rf '$D'" EXIT INT QUIT PIPE
16mkdir -p "$D/boot"
17mkdir -p "$D/efi"
18mkdir -p "$D/sources"
19
20echo 'buzy image' >"$D/sources/linux"
21echo 'the initrd' >"$D/sources/initrd"
22echo 'the-token' >"$D/sources/entry-token"
23echo 'opt1 opt2' >"$D/sources/cmdline"
24
25cat >"$D/sources/install.conf" <<EOF
26layout=bls
27initrd_generator=none
e1b45a75 28# those are overridden by envvars
f875e6bc
ZJS
29BOOT_ROOT="$D/badboot"
30MACHINE_ID=badbadbadbadbadbad6abadbadbadbad
31EOF
32
33export KERNEL_INSTALL_CONF_ROOT="$D/sources"
34export KERNEL_INSTALL_PLUGINS="$plugin"
35export BOOT_ROOT="$D/boot"
8702496b 36export BOOT_MNT="$D/boot"
f875e6bc
ZJS
37export MACHINE_ID='3e0484f3634a418b8e6a39e8828b03e3'
38
39"$kernel_install" -v add 1.1.1 "$D/sources/linux" "$D/sources/initrd"
40
41entry="$BOOT_ROOT/loader/entries/the-token-1.1.1.conf"
42test -f "$entry"
43grep -qE '^title ' "$entry"
44grep -qE '^version +1.1.1' "$entry"
45grep -qE '^options +opt1 opt2' "$entry"
46grep -qE '^linux .*/the-token/1.1.1/linux' "$entry"
47grep -qE '^initrd .*/the-token/1.1.1/initrd' "$entry"
48
49grep -qE 'image' "$BOOT_ROOT/the-token/1.1.1/linux"
50grep -qE 'initrd' "$BOOT_ROOT/the-token/1.1.1/initrd"
51
52"$kernel_install" inspect
53
54"$kernel_install" -v remove 1.1.1
55test ! -f "$entry"
56test ! -f "$BOOT_ROOT/the-token/1.1.1/linux"
57test ! -f "$BOOT_ROOT/the-token/1.1.1/initrd"
58
59# Invoke kernel-install as installkernel
60ln -s --relative -v "$kernel_install" "$D/sources/installkernel"
61"$D/sources/installkernel" -v 1.1.2 "$D/sources/linux" System.map /somedirignored
62
63entry="$BOOT_ROOT/loader/entries/the-token-1.1.2.conf"
64test -f "$entry"
65grep -qE '^title ' "$entry"
66grep -qE '^version +1.1.2' "$entry"
67grep -qE '^options +opt1 opt2' "$entry"
68grep -qE '^linux .*/the-token/1.1.2/linux' "$entry"
69( ! grep -qE '^initrd' "$entry" )
70
71grep -qE 'image' "$BOOT_ROOT/the-token/1.1.2/linux"
72test ! -e "$BOOT_ROOT/the-token/1.1.2/initrd"
73
74# Check installation with boot counting
75echo '56' >"$D/sources/tries"
76
77"$kernel_install" -v add 1.1.1 "$D/sources/linux" "$D/sources/initrd"
78entry="$BOOT_ROOT/loader/entries/the-token-1.1.1+56.conf"
79test -f "$entry"
80grep -qE '^title ' "$entry"
81grep -qE '^version +1.1.1' "$entry"
82grep -qE '^options +opt1 opt2' "$entry"
83grep -qE '^linux .*/the-token/1.1.1/linux' "$entry"
84grep -qE '^initrd .*/the-token/1.1.1/initrd' "$entry"
85
86grep -qE 'image' "$BOOT_ROOT/the-token/1.1.1/linux"
87grep -qE 'initrd' "$BOOT_ROOT/the-token/1.1.1/initrd"
8702496b
LN
88
89if 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"
116fi