#!/bin/sh
set -e
# pass commandline arguments to dpkg-buildpackage
set -x
#pdebuild --debbuildopts "-i\.git -I.git $*"

cat > ~/.pbuilderrc <<EOT
AUTO_DEBSIGN=yes
PKGNAME_LOGFILE=yes
# BUILDRESULT=$BUILDDIR
# HOOKDIR=/home/tillea/.pbuilder -- it's actually /var/cache/pbuilder/hooks
BASEPATH="/var/cache/pbuilder/bullseye-base.cow"
# BINDMOUNTS="/home/vagrant/_pbuilder_local_deps /dev/shm"
# This is a workaround a problem that /dev/shm is not mounted in pbuilder chroot
# BINDMOUNTS="/dev/shm" - set in /etc/pbuilderrc
EOT

STABLEVERSION=""
if [ $# = 1 ] ; then
    STABLEVERSION="-v$1"
fi

/usr/bin/pdebuild --pbuilder cowbuilder --buildresult `dirname \$PWD` --debbuildopts "$STABLEVERSION $SOURCEONLY" --debsign-k "Andreas Tille <tille@debian.org>"
NAME_VER=`dpkg-parsechangelog | awk '/^Source:/ {print $2}'`_`dpkg-parsechangelog | awk '/^Version:/ {print $2}' | sed 's/[0-9]\+://'`
if echo $@ | grep -q -- "-S" ; then
  echo "Building source only upload"
else
  echo "Just do a source upload using ../${NAME_VER}_source.changes"
fi
lintian -i ../${NAME_VER}_*.changes
