#!/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
SOURCE_ONLY_CHANGES=yes
# BUILDRESULT=$BUILDDIR
# HOOKDIR=/home/tillea/.pbuilder -- it's actually /var/cache/pbuilder/hooks
# 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

/usr/bin/pdebuild --pbuilder cowbuilder --buildresult `dirname \$PWD` --debbuildopts "-i\.git -I.git $*" --debsign-k "Andreas Tille <tille@debian.org>"
# /usr/bin/pdebuild --pbuilder cowbuilder --buildresult `dirname \$PWD` --debbuildopts "-i\.git -I.git $*" --debsign-k "Andreas Tille <tille@debian.org>" --debbuildopts -sa
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
