#!/bin/bash
# Invoke shell if build fails and if LGP_AUTO_ENTER_SHELL is set in your ~/.pbuilderrc

. /tmp/hooks/lgp.functions

if [ -n "$LGP_AUTO_ENTER_SHELL" ]; then
	export TERM=linux
	export TMOUT=1200
	export PS1="[$(basename "$SUDO_COMMAND" .dsc) / ${DIST}] \w\$ "
	apt-get install -y --force-yes vim less bash >/dev/null &
	echo
	print_hook "You're entering into the image used to build the package,\n"\
	           "         because LGP_AUTO_ENTER_SHELL has been found in environment."
	echo
	echo "TMOUT set to $TMOUT seconds."
	echo "Type exit or Ctrl-D (i.e. EOF) to escape."
	echo

	cd /tmp/buildd/*/debian/..
	/bin/bash < /dev/tty > /dev/tty 2> /dev/tty
else
	echo "If you want to enter into the chroot image to debug, you have to edit your ~/.pbuilderrc with:"
	echo
	echo "    export LGP_AUTO_ENTER_SHELL=y"
	echo
fi
