From eb5d7730e1b3b1bddecb80be37e5a4c938183f61 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 7 Nov 2022 11:55:29 +0100 Subject: [PATCH 1/4] test: don't ignore non-existent paths in inst_recursive() The process substitution in the while loop hides errors raised by the find utility, which might (and did), in turn, hide errors in test setup. --- test/test-functions | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test-functions b/test/test-functions index 16d9da637b..80ce383e64 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2773,6 +2773,10 @@ inst_recursive() { local p item for p in "$@"; do + # Make sure the source exists, as the process substitution below + # suppresses errors + stat "$p" >/dev/null || return 1 + while read -r item; do if [[ -d "$item" ]]; then inst_dir "$item" From 0c416ea01bc14adff10f4fc5415a36bd2d48f604 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 7 Nov 2022 11:57:59 +0100 Subject: [PATCH 2/4] test: fix locale installation when locale-gen is used locale-gen might merge all compiled locales into a simple archive, so we need to install it as well if necessary. --- test/test-functions | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/test-functions b/test/test-functions index 80ce383e64..45ca472916 100644 --- a/test/test-functions +++ b/test/test-functions @@ -1988,14 +1988,19 @@ install_locales() { inst /usr/share/i18n/SUPPORTED || : inst_recursive /usr/share/i18n/charmaps inst_recursive /usr/share/i18n/locales - inst_recursive /usr/share/locale/en - inst_recursive /usr/share/locale/en_* + inst_recursive /usr/share/locale/en* + inst_recursive /usr/share/locale/de* + image_install /usr/share/locale/locale.alias + # locale-gen might either generate each locale separately or merge them + # into a single archive + if ! (inst_recursive /usr/lib/locale/C.*8 /usr/lib/locale/en_*8 || + image_install /usr/lib/locale/locale-archive); then + dfatal "Failed to install required locales" + exit 1 + fi + else + inst_recursive /usr/lib/locale/C.*8 /usr/lib/locale/en_*8 fi - - inst_recursive /usr/lib/locale/C.utf8 - inst_recursive /usr/lib/locale/C.UTF-8 - inst_recursive /usr/lib/locale/en_*.utf8 - inst_recursive /usr/lib/locale/en_*.UTF-8 } # shellcheck disable=SC2120 From 1edad89399e7cbee230878589ac618103c157ec7 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 7 Nov 2022 12:07:27 +0100 Subject: [PATCH 3/4] test: fix keymaps installation on Arch Where the keymaps live under /usr/share/kbd/keymaps/. --- test/test-functions | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/test/test-functions b/test/test-functions index 45ca472916..194cd682bb 100644 --- a/test/test-functions +++ b/test/test-functions @@ -2007,7 +2007,8 @@ install_locales() { install_keymaps() { local i p local -a prefix=( - "/usr" + "/usr/lib" + "/usr/share" ) dinfo "Install console keymaps" @@ -2016,7 +2017,7 @@ install_keymaps() { && [[ "$(meson configure "${BUILD_DIR:?}" | grep 'split-usr' | awk '{ print $2 }')" == "true" ]] \ || [[ ! -L /lib ]]; then prefix+=( - "" + "/lib" ) fi @@ -2025,12 +2026,12 @@ install_keymaps() { # The first three paths may be deprecated. # It seems now the last three paths are used by many distributions. for i in \ - "$p"/lib/kbd/keymaps/include/* \ - "$p"/lib/kbd/keymaps/i386/include/* \ - "$p"/lib/kbd/keymaps/i386/qwerty/us.* \ - "$p"/lib/kbd/keymaps/legacy/include/* \ - "$p"/lib/kbd/keymaps/legacy/i386/qwerty/us.* \ - "$p"/lib/kbd/keymaps/xkb/us*; do + "$p"/kbd/keymaps/include/* \ + "$p"/kbd/keymaps/i386/include/* \ + "$p"/kbd/keymaps/i386/qwerty/us.* \ + "$p"/kbd/keymaps/legacy/include/* \ + "$p"/kbd/keymaps/legacy/i386/qwerty/us.* \ + "$p"/kbd/keymaps/xkb/us*; do [[ -f "$i" ]] || continue inst "$i" done @@ -2039,10 +2040,10 @@ install_keymaps() { # When it takes any argument, then install more keymaps. for p in "${prefix[@]}"; do for i in \ - "$p"/lib/kbd/keymaps/include/* \ - "$p"/lib/kbd/keymaps/i386/*/* \ - "$p"/lib/kbd/keymaps/legacy/i386/*/* \ - "$p"/lib/kbd/keymaps/xkb/*; do + "$p"/kbd/keymaps/include/* \ + "$p"/kbd/keymaps/i386/*/* \ + "$p"/kbd/keymaps/legacy/i386/*/* \ + "$p"/kbd/keymaps/xkb/*; do [[ -f "$i" ]] || continue inst "$i" done From dbd8dbdfc1d440c44714edcfa513b697f39f4fed Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Sun, 6 Nov 2022 22:40:33 +0100 Subject: [PATCH 4/4] test: cover some interactive/error paths in firstboot --- test/units/testsuite-74.firstboot.sh | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/units/testsuite-74.firstboot.sh b/test/units/testsuite-74.firstboot.sh index 02f9f5cd7a..e2748b1de3 100755 --- a/test/units/testsuite-74.firstboot.sh +++ b/test/units/testsuite-74.firstboot.sh @@ -9,7 +9,7 @@ if ! command -v systemd-firstboot >/dev/null; then fi at_exit() { - if [[ -v ROOT && -n "$ROOT" ]]; then + if [[ -n "${ROOT:-}" ]]; then ls -lR "$ROOT" rm -fr "$ROOT" fi @@ -134,6 +134,30 @@ diff <(awk -F: '/^root/ { print $2; }' /etc/shadow) <(awk -F: '/^root/ { print $ [[ -e /etc/vconsole.conf ]] && diff /etc/vconsole.conf "$ROOT/etc/vconsole.conf" [[ -e /etc/localtime ]] && diff <(readlink /etc/localtime) <(readlink "$ROOT/etc/localtime") +# --prompt-* options +rm -fr "$ROOT" +mkdir -p "$ROOT/bin" +touch "$ROOT/bin/fooshell" "$ROOT/bin/barshell" +# We can do only limited testing here, since it's all an interactive stuff, +# so --prompt and --prompt-root-password are skipped on purpose +echo -ne "\nfoo\nbar\n" | systemd-firstboot --root="$ROOT" --prompt-locale +grep -q "LANG=foo" "$ROOT/etc/locale.conf" +grep -q "LC_MESSAGES=bar" "$ROOT/etc/locale.conf" +echo -ne "\nfoo\n" | systemd-firstboot --root="$ROOT" --prompt-keymap +grep -q "KEYMAP=foo" "$ROOT/etc/vconsole.conf" +echo -ne "\nEurope/Berlin\n" | systemd-firstboot --root="$ROOT" --prompt-timezone +readlink "$ROOT/etc/localtime" | grep -q "Europe/Berlin$" +echo -ne "\nfoobar\n" | systemd-firstboot --root="$ROOT" --prompt-hostname +grep -q "foobar" "$ROOT/etc/hostname" +echo -ne "\n/bin/fooshell\n" | systemd-firstboot --root="$ROOT" --prompt-root-shell +grep -q "^root:.*:0:0:.*:/bin/fooshell$" "$ROOT/etc/passwd" +# Existing files should not get overwritten +echo -ne "\n/bin/barshell\n" | systemd-firstboot --root="$ROOT" --prompt-root-shell +grep -q "^root:.*:0:0:.*:/bin/fooshell$" "$ROOT/etc/passwd" +# Now without the welcome screen but with force +echo -ne "/bin/barshell\n" | systemd-firstboot --root="$ROOT" --force --prompt-root-shell --welcome=no +grep -q "^root:.*:0:0:.*:/bin/barshell$" "$ROOT/etc/passwd" + # Assorted tests rm -fr "$ROOT" mkdir "$ROOT" @@ -143,3 +167,7 @@ grep -E "[a-z0-9]{32}" "$ROOT/etc/machine-id" systemd-firstboot --root="$ROOT" --delete-root-password diff <(echo) <(awk -F: '/^root/ { print $2; }' "$ROOT/etc/shadow") + +(! systemd-firstboot --root="$ROOT" --root-shell=/bin/nonexistentshell) +(! systemd-firstboot --root="$ROOT" --machine-id=invalidmachineid) +(! systemd-firstboot --root="$ROOT" --timezone=Foo/Bar)