#!/bin/sh

B=progress-linux-base-system_20221002-20.1_amd64.deb
D=progress-linux-container_20221002-20.1_all.deb

set -eu

if test -n "${1:-}"; then
	bad=$(dpkg --root="$1" --verify)
	if test -n "$bad"; then
		echo "$bad"
		exit 1
	fi
	exit 0
fi

bootstrap_test() {
	echo "test case $*"
	suite="$1"
	shift
	mmdebstrap --verbose --variant=apt "$suite" /dev/null --customize-hook="upload $B /b.deb" --customize-hook="upload $D /p.deb" "$@" --customize-hook="$0"
}

PREINTS_OPT=--include=progress-linux-container
INST_OPT="--chrooted-customize-hook=apt-get -y install /b.deb /p.deb"

# install on unstable
bootstrap_test unstable "$INST_OPT"

# install on bookworm
bootstrap_test bookworm "$INST_OPT"

# upgrade unstable to fixed
bootstrap_test unstable "$PREINTS_OPT" "$INST_OPT"

# progress-linux is missing from bookworm. cannot upgrade
