#!/bin/sh
set -xe

. /etc/os-release
dist=${ID:-unknown}
ver=${VERSION_CODENAME:-unknown}

export DEBIAN_FRONTEND=noninteractive

apt update --allow-releaseinfo-change
apt -y install devscripts dpkg-dev equivs
mk-build-deps --install --remove \
    --tool "apt-get -o Debug::pkgProblemResolver=yes -q -y" \
    debian/control

# Install additional libs
apt install -y tzdata
apt install -y libmaxmind-db-reader-perl || true
apt install -y libhttp-browserdetect-perl || true
apt install -y libauthen-webauthn-perl || true

make debian-packages

mkdir -p "result/$dist/$ver/"
cp /tmp/*deb  "result/$dist/$ver/"
