2020-03-04 09:35:06 +00:00
#!/usr/bin/env bash
2021-10-17 18:13:06 +02:00
# SPDX-License-Identifier: LGPL-2.1-or-later
2021-03-05 18:36:04 +09:00
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh
2021-04-09 19:39:41 +02:00
set -eux
2019-03-07 14:47:43 +09:00
set -o pipefail
2021-09-30 14:14:19 +02:00
ARGS = ( )
if [ [ -v ASAN_OPTIONS || -v UBSAN_OPTIONS ] ] ; then
# If we're running under sanitizers, we need to use a less restrictive
# profile, otherwise LSan syscall would get blocked by seccomp
ARGS += ( --profile= trusted)
fi
2021-11-23 16:34:40 +01:00
systemd-dissect --no-pager /usr/share/minimal_0.raw | grep -q '✓ portable service'
systemd-dissect --no-pager /usr/share/minimal_1.raw | grep -q '✓ portable service'
systemd-dissect --no-pager /usr/share/app0.raw | grep -q '✓ extension for portable service'
systemd-dissect --no-pager /usr/share/app1.raw | grep -q '✓ extension for portable service'
2021-03-05 18:36:04 +09:00
export SYSTEMD_LOG_LEVEL = debug
2021-07-22 20:41:34 +01:00
mkdir -p /run/systemd/system/systemd-portabled.service.d/
cat <<EOF >/run/systemd/system/systemd-portabled.service.d/override.conf
[ Service]
Environment = SYSTEMD_LOG_LEVEL = debug
EOF
2019-03-07 14:47:43 +09:00
2021-09-30 14:14:19 +02:00
portablectl " ${ ARGS [@] } " attach --now --runtime /usr/share/minimal_0.raw app0
2019-03-07 14:47:43 +09:00
2021-03-05 18:36:04 +09:00
systemctl is-active app0.service
systemctl is-active app0-foo.service
set +o pipefail
set +e
systemctl is-active app0-bar.service && exit 1
set -e
set -o pipefail
2021-09-30 14:14:19 +02:00
portablectl " ${ ARGS [@] } " reattach --now --runtime /usr/share/minimal_1.raw app0
2021-03-05 18:36:04 +09:00
systemctl is-active app0.service
systemctl is-active app0-bar.service
set +o pipefail
set +e
systemctl is-active app0-foo.service && exit 1
set -e
set -o pipefail
2019-03-07 14:47:43 +09:00
2021-03-05 18:36:04 +09:00
portablectl list | grep -q -F "minimal_1"
2019-03-07 14:47:43 +09:00
2021-03-05 18:36:04 +09:00
portablectl detach --now --runtime /usr/share/minimal_1.raw app0
2019-03-07 14:47:43 +09:00
2021-03-05 18:36:04 +09:00
portablectl list | grep -q -F "No images."
2019-03-07 14:47:43 +09:00
2021-03-05 18:36:04 +09:00
# portablectl also works with directory paths rather than images
2019-03-07 14:47:43 +09:00
2021-03-05 18:36:04 +09:00
unsquashfs -dest /tmp/minimal_0 /usr/share/minimal_0.raw
unsquashfs -dest /tmp/minimal_1 /usr/share/minimal_1.raw
2019-03-07 14:47:43 +09:00
2021-09-30 14:14:19 +02:00
portablectl " ${ ARGS [@] } " attach --copy= symlink --now --runtime /tmp/minimal_0 app0
2019-03-07 14:47:43 +09:00
2021-03-05 18:36:04 +09:00
systemctl is-active app0.service
systemctl is-active app0-foo.service
set +o pipefail
set +e
systemctl is-active app0-bar.service && exit 1
set -e
set -o pipefail
2021-09-30 14:14:19 +02:00
portablectl " ${ ARGS [@] } " reattach --now --enable --runtime /tmp/minimal_1 app0
2021-03-05 18:36:04 +09:00
systemctl is-active app0.service
systemctl is-active app0-bar.service
set +o pipefail
set +e
systemctl is-active app0-foo.service && exit 1
set -e
set -o pipefail
2019-03-07 14:47:43 +09:00
2021-03-05 18:36:04 +09:00
portablectl list | grep -q -F "minimal_1"
2020-09-14 15:44:30 +09:00
2021-03-05 18:36:04 +09:00
portablectl detach --now --enable --runtime /tmp/minimal_1 app0
2020-09-14 15:44:30 +09:00
2021-03-05 18:36:04 +09:00
portablectl list | grep -q -F "No images."
2020-09-14 15:44:30 +09:00
2021-09-30 14:14:19 +02:00
portablectl " ${ ARGS [@] } " attach --now --runtime --extension /usr/share/app0.raw /usr/share/minimal_0.raw app0
2020-06-23 13:09:42 +01:00
2021-07-22 20:41:34 +01:00
systemctl is-active app0.service
2021-09-30 14:14:19 +02:00
portablectl " ${ ARGS [@] } " reattach --now --runtime --extension /usr/share/app0.raw /usr/share/minimal_1.raw app0
2021-07-22 20:41:34 +01:00
systemctl is-active app0.service
portablectl detach --now --runtime --extension /usr/share/app0.raw /usr/share/minimal_1.raw app0
2021-09-30 14:14:19 +02:00
portablectl " ${ ARGS [@] } " attach --now --runtime --extension /usr/share/app1.raw /usr/share/minimal_0.raw app1
2020-06-23 13:09:42 +01:00
systemctl is-active app1.service
2021-09-30 14:14:19 +02:00
portablectl " ${ ARGS [@] } " reattach --now --runtime --extension /usr/share/app1.raw /usr/share/minimal_1.raw app1
2020-06-23 13:09:42 +01:00
systemctl is-active app1.service
2021-07-22 20:41:34 +01:00
portablectl detach --now --runtime --extension /usr/share/app1.raw /usr/share/minimal_1.raw app1
2020-06-23 13:09:42 +01:00
# portablectl also works with directory paths rather than images
2021-11-23 16:34:40 +01:00
mkdir /tmp/rootdir /tmp/app1 /tmp/overlay /tmp/os-release-fix /tmp/os-release-fix/etc
2021-07-22 20:41:34 +01:00
mount /usr/share/app1.raw /tmp/app1
mount /usr/share/minimal_0.raw /tmp/rootdir
2021-11-23 16:34:40 +01:00
# Fix up os-release to drop the valid PORTABLE_SERVICES field (because we are
# bypassing the sysext logic in portabled here it will otherwise not see the
# extensions additional valid prefix)
grep -v "^PORTABLE_PREFIXES=" /tmp/rootdir/etc/os-release > /tmp/os-release-fix/etc/os-release
mount -t overlay overlay -o lowerdir = /tmp/os-release-fix:/tmp/app1:/tmp/rootdir /tmp/overlay
grep . /tmp/overlay/usr/lib/extension-release.d/*
grep . /tmp/overlay/etc/os-release
2020-06-23 13:09:42 +01:00
2021-09-30 14:14:19 +02:00
portablectl " ${ ARGS [@] } " attach --copy= symlink --now --runtime /tmp/overlay app1
2020-06-23 13:09:42 +01:00
systemctl is-active app1.service
portablectl detach --now --runtime overlay app1
umount /tmp/overlay
umount /tmp/rootdir
umount /tmp/app1
2021-04-08 00:09:55 +02:00
echo OK >/testok
2019-03-07 14:47:43 +09:00
exit 0