File: integration-test-setup.sh

package info (click to toggle)
systemd-udeb 259-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 104,120 kB
  • sloc: ansic: 726,480; xml: 121,118; python: 35,852; sh: 33,447; cpp: 946; awk: 102; makefile: 89; lisp: 13; sed: 1
file content (61 lines) | stat: -rwxr-xr-x 2,278 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eu
set -o pipefail

case "$1" in
    setup)
        busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager SetShowStatus s no

        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)
                    DEBIAN_FRONTEND=noninteractive apt-get -y 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)
        busctl call org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager SetShowStatus s auto

        # 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