#!/bin/bash -e

case "$1" in
	--build | -b)
		if grep -qs '^Purpose: PPA' /CurrentlyBuilding; then
			NO_PKG_MANGLE=1
			echo "INFO: Disabling pkgbinarymangler for PPA build"
		fi
                if grep -q '^Section: partner' debian/control; then
                        NO_PKG_MANGLE=1
                        echo "INFO: Disabling pkgbinarymangler for partner packages"
                fi
		if [ -z "$NO_PKG_MANGLE" ]; then
			if [ -x /usr/bin/pkgstriptranslations ]; then
				/usr/bin/pkgstriptranslations
			else
				echo "ERROR: dpkg-deb is diverted, but /usr/bin/pkgstriptranslations"
				echo "ERROR: is not executable; please check your configuration"
				exit 1
			fi
		else
			echo "WARNING: not running pkgstriptranslations for this package, as requested"
		fi
		;;
	*)
		;;
esac

exec -a /usr/bin/dpkg-deb /usr/bin/dpkg-deb.pkgstriptranslations "$@"
