#!/bin/sh
# Copyright 2022 Simon McVittie
# SPDX-License-Identifier: GPL-2.0-or-later

set -eu

if dpkg-vendor --is ubuntu; then
    vendor=ubuntu
    suite=$(ubuntu-distro-info --latest)
else
    # default to Debian
    vendor=debian
    suite=testing
fi

if [ -z "${AUTOPKGTEST_TEST_UNINSTALLED-}" ]; then
    export AUTOPKGTEST_TEST_INSTALLED=yes
    build_podman=autopkgtest-build-podman
else
    build_podman=tools/autopkgtest-build-podman
fi

if ! "$build_podman" --vendor="$vendor" --release="$suite"; then
    echo "SKIP: Unable to build autopkgtest/$vendor:$suite container"
    exit 77
fi

export AUTOPKGTEST_TEST_PODMAN="autopkgtest/$vendor:$suite"
export PYTHONUNBUFFERED=1
# Wrapping the test in annotate-output helps to distinguish the output of
# the autopkgtest that is running these tests from the output of the
# autopkgtest that is under test.
exec annotate-output ./tests/autopkgtest PodmanRunner
