#!/bin/bash

set -e

if ! grep -qs ^debusine-worker: /etc/subuid; then
	# unshare needs /etc/subuid and /etc/subgid, and this is only set up
	# on our debusine-worker for >= bookworm (see
	# debusine-worker.postinst for more information)
	echo 'unshare-based tests require Debian >= bookworm' >&2
	exit 77  # tell autopkgtest to skip test
fi

source debian/tests/utils/add-debusine-log-files-to-artifacts.sh

adduser debusine-worker sbuild

# set up schroot (for sbuild)
sbuild-createchroot stable /srv/chroot/stable

# set up schroot (for autopkgtest)
sbuild-createchroot bookworm /srv/chroot/bookworm

# autopkgtest schroot needs to be ephemeral
sed -i -e 's,^union-type=none,union-type=overlay,' /etc/schroot/chroot.d/bookworm-*
echo "union-overlay-directory=/dev/shm" >> /etc/schroot/chroot.d/bookworm-*

debian/tests/utils/integration-tests-setup-debusine-all.sh

# To make autopkgtest faster on salsa: use xz faster compression
mkdir /lib/systemd/system/debusine-worker.service.d/
(echo "[Service]" ; echo 'Environment="XZ_OPT=-0"') >> \
	/lib/systemd/system/debusine-worker.service.d/autopkgtest.conf
systemctl daemon-reload
systemctl restart debusine-worker

# The autopkgtest, sbuild and lintian  tests depend on the mmdebstrap tests
# having run first (see find_system_image).
debian/tests/integration-tests-task-mmdebstrap.py -v

debian/tests/integration-tests-task-autopkgtest.py -v

debian/tests/integration-tests-task-sbuild.py -v

debian/tests/integration-tests-task-lintian.py -v

debian/tests/integration-tests-task-piuparts.py -v

debian/tests/integration-tests-task-blhc.py -v
