#!/bin/bash

set -e

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

# work around debos/fakemachine needed systemd-resolved
# but installing it breaks network connection for salsa-ci
if [ ! -f /lib/systemd/systemd-resolved ]; then
	cp /etc/resolv.conf /etc/resolv.conf.backup
	systemctl mask systemd-resolved.service
	apt-get install -y systemd-resolved
	mv /etc/resolv.conf.backup /etc/resolv.conf
fi

if [ ! -w /dev/kvm ]; then
	apt-get install -y libslirp-helper user-mode-linux
	if dpkg --compare-versions "$(dpkg-query -W -f'${Version}' user-mode-linux)" ge 6.11um1 && \
	   ! zgrep -q 1086194 /usr/share/doc/user-mode-linux/changelog.Debian.gz; then
		echo "Skipping: UML 6.11 cannot mount hostfs: https://bugs.debian.org/1086194" >&2
		exit 77
	fi
fi

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

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