#!/bin/bash
# script for pbuilder to create upload directory
workdir=$1
oldversion=$2
newversion=$3
if [ -z "$3" ] ; then
   echo usage: pbuilderscript workdir oldversion newversion
   exit 1
fi
cd "$workdir" || exit 1
echo "working in `pwd`"
export DEBEMAIL=wvermin@gmail.com
export DEBFULLNAME="Willem Vermin"
sed -i 's/^#//' /etc/apt/sources.list   # oncomment 2de regel
apt update
apt -y install apt-utils || exit 1
apt -y install quilt devscripts debhelper autotools-dev equivs || exit 1
apt source findent || exit 1
cd findent-$oldversion || exit 1
uupdate -v $newversion ../findent-$newversion.tar.gz || exit 1
cd ../findent-$newversion
if [ -d debian.upstream ] ; then
   rm -r debian
   mv debian.upstream debian || exit 1
fi
#apt -y install vim
#echo dpkg-source ...
#dpkg-source --commit
echo quilt ...
while quilt push; do quilt refresh; done
#dch
echo | mk-build-deps --install --remove debian/control || exit 1
rm -f *-build-deps*.buildinfo *-build-deps*.changes
# got dpkg-source: error: aborting due to unexpected upstream changes
# caused by the files *-build-deps*.buildinfo and *-build-deps*.changes
# created by mk-build-deps
# hence the following:
# but the offending files are already discarded above ....
if false ; then
   if false ; then
      # this seems to be the recommended way
      mkdir -p debian/source
      (
      echo "Description: to remedy this"
      echo "  dpkg-source: error: aborting due to unexpected upstream changes"
      echo "Forwarded: not-needed"
      ) > debian/source/local-patch-header
      EDITOR=/bin/true dpkg-source --commit . buildinfo-changes
      while quilt push; do quilt refresh; done
      #
   else
      # simple remove the offending files
      rm -f *-build-deps*.buildinfo *-build-deps*.changes
   fi
fi

#dpkg-source --commit
#while quilt push; do quilt refresh; done
#dpkg-buildpackage -us -uc
# lintian option -F : only tags that prevent upload to debian
debuild -us -uc --lintian-opts -F
if false ; then
   # debuild already runs lintian
   cd ..
   echo "running lintian ..."
   lintian -F -i -I --show-overrides --no-tag-display-limit findent_$newversion-1_amd64.changes
   echo "end lintian"
fi
echo $0 done
