#!/bin/bash -e
#
# cowbuilder helper for git-buildpackage
#
# This is only left here for compatibility. Better use git-pbuilder instead.

echo "***"
echo "  This script is deprecated."
echo "  Please switch to /usr/bin/git-pbuilder"
echo "  See file:///usr/share/doc/git-buildpackage/manual-html/gbp.special.html#GBP.SPECIAL.PBUILDER"
echo "***"

DIST=${0/*gbp-cowbuilder-}
ACTION=$1

CONF=/etc/pbuilder/pbuilderrc.$DIST
WA_OPT='--debian-etch-workaround'

case $DIST in
	sarge*|etch*)
		echo "`basename $0`: Using $WA_OPT"
    		OPTS="$OPTS $WA_OPT"
		;;
esac

case $ACTION in
    update|create|login)
	sudo cowbuilder --$ACTION --configfile=${CONF} --dist $DIST
	;;
    *)
	# pass all options to dpkg-buildpackage:
	pdebuild --configfile ${CONF} 		     \
	 	--pbuilder cowbuilder                \
		--buildresult ${GBP_BUILD_DIR}/..    \
		--debbuildopts "-i -I $*"            \
		-- $OPTS
	;;
esac

