#!/bin/bash
# example file to be used with --hookdir
#
# try to install the resulting debs.

echo "Trying to install resulting packages and test upgrades"
set -ex

BUILDDIR="${BUILDDIR:-/tmp/buildd}"

PKGNAMES=$(cd "$BUILDDIR" && ls -1 *.deb | sed 's/_.*$//' )

# install the resulting debs and their dependencies
# this may fail, but this is fine as if it fails here it will also fail, again, later.
apt-get install -f -y "${APTGETOPT[@]}" "$BUILDDIR"/*.deb || true

# install-remove check
dpkg -i "$BUILDDIR"/*.deb
dpkg --remove $PKGNAMES

# install-purge check
dpkg -i "$BUILDDIR"/*.deb
dpkg --purge $PKGNAMES

# upgrade-remove check
apt-get install -y "${APTGETOPT[@]}" $PKGNAMES || true
dpkg -i "$BUILDDIR"/*.deb
dpkg --remove $PKGNAMES

# upgrade-purge check
apt-get install -y "${APTGETOPT[@]}" $PKGNAMES || true
dpkg -i "$BUILDDIR"/*.deb
dpkg --purge $PKGNAMES
