#!/bin/sh
set -e

# The following issues won't be fixed in squeeze:
#   - unconditional use of deluser during postrm purge
#   - unconditional use of ucf during postrm purge
# so add these packages to the "fake" essential set.
USED_DURING_PURGE="adduser ucf"

FAILS_TO_REMOVE=


case ${PIUPARTS_OBJECTS%%=*} in
	TARBALL)
		# don't install fake essential packages while creating the tarball
		exit 0
		;;
	adduser|ucf)
		# allow testing of the fake essential packages
		exit 0
		;;
	mediamate)
		# removed after lenny
		#574228: mediamate: package purge (after dependencies removal) fails
		USED_DURING_PURGE="$USED_DURING_PURGE wwwconfig-common"
		;;
	phpbb3)
		USED_DURING_PURGE="$USED_DURING_PURGE dbconfig-common"
		;;
	prelude-manager)
		#660455
		USED_DURING_PURGE="$USED_DURING_PURGE dbconfig-common"
		;;
esac

# work around #601961: apt: wrongly thinks install-info is essential
case ${PIUPARTS_DISTRIBUTION} in
	squeeze|squeeze-lts)
		# there is no install-info in lenny
		FAILS_TO_REMOVE="$FAILS_TO_REMOVE install-info"
		;;
esac

echo "*** Adding fake essential packages ***"
apt-get install -yf $USED_DURING_PURGE $FAILS_TO_REMOVE
