summaryrefslogtreecommitdiffstats
path: root/test/integration-test-setup.sh
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-16 18:25:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-16 18:25:59 +0000
commit1e34d75027c0773e21b35688c27034d5af5e635c (patch)
tree7f3e33142d7a4d06037846454f08b1b0350b2a95 /test/integration-test-setup.sh
parentAdding upstream version 256.4. (diff)
downloadsystemd-1e34d75027c0773e21b35688c27034d5af5e635c.tar.xz
systemd-1e34d75027c0773e21b35688c27034d5af5e635c.zip
Adding upstream version 256.5.upstream/256.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration-test-setup.sh')
-rwxr-xr-xtest/integration-test-setup.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/integration-test-setup.sh b/test/integration-test-setup.sh
new file mode 100755
index 0000000..d7c384a
--- /dev/null
+++ b/test/integration-test-setup.sh
@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: LGPL-2.1-or-later
+set -eux
+set -o pipefail
+
+case "$1" in
+ setup)
+ if [[ -f "$STATE_DIRECTORY/inprogress" ]]; then
+ exit 0
+ fi
+
+ if [[ -d /snapshot ]]; then
+ echo "Run systemctl soft-reboot first to make sure the test runs within a pristine rootfs" >&2
+ exit 1
+ fi
+
+ . /usr/lib/os-release
+
+ if test -n "$(shopt -s nullglob; echo /work/build/*.{rpm,deb,pkg.tar})"; then
+ case "$ID" in
+ arch)
+ pacman --upgrade --needed --noconfirm /work/build/*.pkg.tar
+ ;;
+ debian|ubuntu)
+ apt-get install /work/build/*.deb
+ ;;
+ opensuse*)
+ zypper --non-interactive install --allow-unsigned-rpm /work/build/*.rpm
+ ;;
+ centos|fedora)
+ dnf upgrade --assumeyes --disablerepo="*" /work/build/*.rpm
+ ;;
+ *)
+ echo "Unknown distribution $ID" >&2
+ exit 1
+ esac
+ fi
+
+ # TODO: Use a proper flat btrfs subvolume layout once we can create subvolumes without privileged in
+ # systemd-repart (see https://github.com/systemd/systemd/pull/33498). Until that's possible, we nest
+ # snapshots within each other.
+ if command -v btrfs >/dev/null && [[ "$(stat --file-system --format %T /)" == "btrfs" ]]; then
+ btrfs subvolume snapshot / /snapshot
+ fi
+
+ touch "$STATE_DIRECTORY/inprogress"
+ ;;
+ finalize)
+ # If we're rebooting, the test does a reboot as part of its execution and we shouldn't remove /inprogress.
+ if ! [[ "$(systemctl list-jobs)" =~ reboot.target|kexec.target|soft-reboot.target ]]; then
+ rm -f "$STATE_DIRECTORY/inprogress"
+ fi
+ ;;
+ *)
+ echo "Unknown verb $1" >&2
+ exit 1
+esac