#!/bin/sh -ex

test -f setup.py || test -f pyproject.toml
test ! -e debian
rm -rf deb_dist
python3 setup.py --command-packages=stdeb.command debianize --suite smurf --maintainer "Matthias Urlichs <matthias@urlichs.de>" -c 13 "$@"

cat >debian/.gitignore <<_
/files
/*.log
/*.debhelper
/*.debhelper-build-stamp
/*.substvars
/debhelper-build-stamp
_
echo 13 >debian/compat
sed -ne 's#^Package: #/#p' <debian/control >>debian/.gitignore
sed -i -e 's#buildsystem=.*#buildsystem=pybuild#' debian/rules

T=$(mktemp)
if uniq < debian/control > $T ; then
	mv $T debian/control
else
	rm -f $T
	exit 1
fi

fgrep -qs .pybuild .gitignore || echo '/.pybuild/' >>.gitignore	
git add debian .gitignore
git commit -m "Debianized."
echo DONE
