#!/bin/sh

if test ! -f setup.py ; then
	echo "setup.py: not found" >&2
	exit 1
fi

rm -rf deb_dist
N="$(python setup.py --name)"

tmp=$(tempfile)
trap 'rm -f $tmp' 0
if test $(git ls-files --exclude-standard --modified --others | wc -l) -ne 0 ; then
	echo "You have unsaved changes. Exiting." >&2
	git status
	exit 1
fi

for x in pyo pyc swp swo ; do
fgrep -qs .$x .gitignore || echo "*.$x" >>.gitignore
done
fgrep -qs egg-info .gitignore || echo "/$N.egg-info/" >>.gitignore
fgrep -qs /.pybuild .gitignore || echo "/.pybuild/" >>.gitignore
fgrep -qs /build .gitignore || echo "/build/" >>.gitignore
git add .gitignore
git commit -m "Ignore built files" .gitignore

if test ! -d debian ; then
	rapydcss.egg-info/
	python setup.py --command-packages=stdeb.command debianize --suite smurf --with-python2 true --with-python3 true
	git add debian
	git commit -m "auto-Debianized"
	git-push-init-netz
	git remote add github git@github.com:smurfix/$N.git
	if git fetch github ; then
		git config remote.github.push "refs/heads/*:refs/heads/*"
	else
		echo "*** no github repo ***" >&2
		git remote rm github
	fi
	cat <<END >debian/.gitignore
/files
/*.log
/*.debhelper
/*.substvars
/python-$N/
/python3-$N/
END
    

	git add debian/.gitignore .gitignore
	git commit -m "ignore some Debian build files" debian/.gitignore .gitignore
	git-push-all
fi
#debch

