hwdb: fix screen rotation for EXO Wings 2in1 w1125 (#36283)
[systemd.io.git] / test / units / TEST-29-PORTABLE.directory.sh
blob5458111ee201d8d2a97c8d4b15ef330f31a540b5
1 #!/usr/bin/env bash
2 # SPDX-License-Identifier: LGPL-2.1-or-later
3 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
4 # ex: ts=8 sw=4 sts=4 et filetype=sh
5 # shellcheck disable=SC2233,SC2235
6 set -eux
7 set -o pipefail
9 # shellcheck source=test/units/util.sh
10 . "$(dirname "$0")"/util.sh
12 # Arrays cannot be exported, so redefine in each test script
13 ARGS=()
14 if [[ -v ASAN_OPTIONS || -v UBSAN_OPTIONS ]]; then
15 # If we're running under sanitizers, we need to use a less restrictive
16 # profile, otherwise LSan syscall would get blocked by seccomp
17 ARGS+=(--profile=trusted)
20 unsquashfs -dest /tmp/minimal_0 /usr/share/minimal_0.raw
21 unsquashfs -dest /tmp/minimal_1 /usr/share/minimal_1.raw
23 portablectl "${ARGS[@]}" attach --copy=symlink --now --runtime /tmp/minimal_0 minimal-app0
25 systemctl is-active minimal-app0.service
26 systemctl is-active minimal-app0-foo.service
27 systemctl is-active minimal-app0-bar.service && exit 1
29 portablectl "${ARGS[@]}" reattach --now --enable --runtime /tmp/minimal_1 minimal-app0
31 systemctl is-active minimal-app0.service
32 systemctl is-active minimal-app0-bar.service
33 systemctl is-active minimal-app0-foo.service && exit 1
35 portablectl list | grep -q -F "minimal_1"
36 busctl tree org.freedesktop.portable1 --no-pager | grep -q -F '/org/freedesktop/portable1/image/minimal_5f1'
38 portablectl detach --now --enable --runtime /tmp/minimal_1 minimal-app0
40 portablectl list | grep -q -F "No images."
41 busctl tree org.freedesktop.portable1 --no-pager | grep -q -F '/org/freedesktop/portable1/image/minimal_5f1' && exit 1
43 mkdir /tmp/rootdir /tmp/app0 /tmp/app1 /tmp/overlay /tmp/os-release-fix /tmp/os-release-fix/etc
44 mount /tmp/app0.raw /tmp/app0
45 mount /tmp/app1.raw /tmp/app1
46 mount /usr/share/minimal_0.raw /tmp/rootdir
48 # Fix up os-release to drop the valid PORTABLE_SERVICES field (because we are
49 # bypassing the sysext logic in portabled here it will otherwise not see the
50 # extensions additional valid prefix)
51 grep -v "^PORTABLE_PREFIXES=" /tmp/rootdir/etc/os-release >/tmp/os-release-fix/etc/os-release
53 mount -t overlay overlay -o lowerdir=/tmp/os-release-fix:/tmp/app1:/tmp/rootdir /tmp/overlay
55 grep . /tmp/overlay/usr/lib/extension-release.d/*
56 grep . /tmp/overlay/etc/os-release
58 portablectl "${ARGS[@]}" attach --copy=symlink --now --runtime /tmp/overlay app1
60 systemctl is-active app1.service
62 portablectl detach --now --runtime overlay app1
64 # Ensure --force works also when symlinking
65 mkdir -p /run/systemd/system.attached/app1.service.d
66 cat <<EOF >/run/systemd/system.attached/app1.service
67 [Unit]
68 Description=App 1
69 EOF
70 cat <<EOF >/run/systemd/system.attached/app1.service.d/10-profile.conf
71 [Unit]
72 Description=App 1
73 EOF
74 cat <<EOF >/run/systemd/system.attached/app1.service.d/20-portable.conf
75 [Unit]
76 Description=App 1
77 EOF
78 systemctl daemon-reload
80 portablectl "${ARGS[@]}" attach --force --copy=symlink --now --runtime /tmp/overlay app1
82 systemctl is-active app1.service
84 portablectl detach --now --runtime overlay app1
86 umount /tmp/overlay
88 portablectl "${ARGS[@]}" attach --copy=symlink --now --runtime --extension /tmp/app0 --extension /tmp/app1 /tmp/rootdir app0 app1
90 systemctl is-active app0.service
91 systemctl is-active app1.service
93 portablectl inspect --cat --extension app0 --extension app1 rootdir app0 app1 | grep -q -f /tmp/rootdir/usr/lib/os-release
94 portablectl inspect --cat --extension app0 --extension app1 rootdir app0 app1 | grep -q -f /tmp/app0/usr/lib/extension-release.d/extension-release.app0
95 portablectl inspect --cat --extension app0 --extension app1 rootdir app0 app1 | grep -q -f /tmp/app1/usr/lib/extension-release.d/extension-release.app2
96 portablectl inspect --cat --extension app0 --extension app1 rootdir app0 app1 | grep -q -f /tmp/app1/usr/lib/systemd/system/app1.service
97 portablectl inspect --cat --extension app0 --extension app1 rootdir app0 app1 | grep -q -f /tmp/app0/usr/lib/systemd/system/app0.service
99 grep -q -F "LogExtraFields=PORTABLE=app0" /run/systemd/system.attached/app0.service.d/20-portable.conf
100 grep -q -F "LogExtraFields=PORTABLE_ROOT=rootdir" /run/systemd/system.attached/app0.service.d/20-portable.conf
101 grep -q -F "LogExtraFields=PORTABLE_EXTENSION=app0" /run/systemd/system.attached/app0.service.d/20-portable.conf
102 grep -q -F "LogExtraFields=PORTABLE_EXTENSION_NAME_AND_VERSION=app" /run/systemd/system.attached/app0.service.d/20-portable.conf
103 grep -q -F "LogExtraFields=PORTABLE_EXTENSION=app1" /run/systemd/system.attached/app0.service.d/20-portable.conf
104 grep -q -F "LogExtraFields=PORTABLE_EXTENSION_NAME_AND_VERSION=app_1" /run/systemd/system.attached/app0.service.d/20-portable.conf
106 grep -q -F "LogExtraFields=PORTABLE=app1" /run/systemd/system.attached/app1.service.d/20-portable.conf
107 grep -q -F "LogExtraFields=PORTABLE_ROOT=rootdir" /run/systemd/system.attached/app1.service.d/20-portable.conf
108 grep -q -F "LogExtraFields=PORTABLE_EXTENSION=app0" /run/systemd/system.attached/app1.service.d/20-portable.conf
109 grep -q -F "LogExtraFields=PORTABLE_EXTENSION_NAME_AND_VERSION=app" /run/systemd/system.attached/app1.service.d/20-portable.conf
110 grep -q -F "LogExtraFields=PORTABLE_EXTENSION=app1" /run/systemd/system.attached/app1.service.d/20-portable.conf
111 grep -q -F "LogExtraFields=PORTABLE_EXTENSION_NAME_AND_VERSION=app_1" /run/systemd/system.attached/app1.service.d/20-portable.conf
113 portablectl detach --clean --now --runtime --extension /tmp/app0 --extension /tmp/app1 /tmp/rootdir app0 app1
115 # Ensure --clean remove state and other directories belonging to the portable image being detached
116 test ! -d /var/lib/app0
117 test ! -d /run/app0
119 # Ensure that mixed mode copies the images and units (client-owned) but symlinks the profile (OS owned)
120 portablectl "${ARGS[@]}" attach --copy=mixed --runtime --extension /tmp/app0 --extension /tmp/app1 /tmp/rootdir app0 app1
121 test -d /run/portables/app0
122 test -d /run/portables/app1
123 test -d /run/portables/rootdir
124 test -f /run/systemd/system.attached/app0.service
125 test -f /run/systemd/system.attached/app1.service
126 test -L /run/systemd/system.attached/app0.service.d/10-profile.conf
127 test -L /run/systemd/system.attached/app1.service.d/10-profile.conf
128 portablectl detach --runtime --extension /tmp/app0 --extension /tmp/app1 /tmp/rootdir app0 app1
130 # Attempt to disable the app unit during detaching. Requires --copy=symlink to reproduce.
131 # Provides coverage for https://github.com/systemd/systemd/issues/23481
132 portablectl "${ARGS[@]}" attach --copy=symlink --now --runtime /tmp/rootdir minimal-app0
133 portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
134 # attach and detach again to check if all drop-in configs are removed even if the main unit files are removed
135 portablectl "${ARGS[@]}" attach --copy=symlink --now --runtime /tmp/rootdir minimal-app0
136 portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
138 # The wrong file should be ignored, given the right one has the xattr set
139 trap 'rm -rf /var/cache/wrongext' EXIT
140 mkdir -p /var/cache/wrongext/usr/lib/extension-release.d /var/cache/wrongext/usr/lib/systemd/system/
141 echo "[Service]" > /var/cache/wrongext/usr/lib/systemd/system/app0.service
142 touch /var/cache/wrongext/usr/lib/extension-release.d/extension-release.wrongext_somethingwrong.txt
143 cp /tmp/rootdir/usr/lib/os-release /var/cache/wrongext/usr/lib/extension-release.d/extension-release.app0
144 setfattr -n user.extension-release.strict -v "false" /var/cache/wrongext/usr/lib/extension-release.d/extension-release.app0
145 portablectl "${ARGS[@]}" attach --runtime --extension /var/cache/wrongext /tmp/rootdir app0
146 status="$(portablectl is-attached --extension wrongext rootdir)"
147 [[ "${status}" == "attached-runtime" ]]
148 portablectl detach --runtime --extension /var/cache/wrongext /tmp/rootdir app0
150 umount /tmp/rootdir
151 umount /tmp/app0
152 umount /tmp/app1