#!/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
	dpkg)
		# don't install fake essential packages while creating the tarball
		exit 0
		;;
	adduser|ucf)
		# allow testing of the fake essential packages
		exit 0
		;;
	gosa-desktop|kde-core|kde-full|kde-plasma-desktop|kde-standard|kdebase-apps|konqueror|konq-plugins|mozart-doc|texlive-full)
		# work around #601961: apt: wrongly thinks install-info is essential
		case ${PIUPARTS_DISTRIBUTION} in
			squeeze|squeeze-lts)
				FAILS_TO_REMOVE="$FAILS_TO_REMOVE install-info"
				;;
		esac
		;;
	docbookwiki)
		USED_DURING_PURGE="$USED_DURING_PURGE mysql-client"
		;;
	phpbb3)
		USED_DURING_PURGE="$USED_DURING_PURGE dbconfig-common"
		;;
	prelude-manager)
		#WORKSAROUND #660455
		USED_DURING_PURGE="$USED_DURING_PURGE dbconfig-common"
		;;
	drupal6|moodle|moodle-book|moodle-debian-edu-theme|scuttle)
		if [ "$PIUPARTS_DISTRIBUTION" = "lenny" ]; then
			USED_DURING_PURGE="$USED_DURING_PURGE wwwconfig-common"
		fi
		;;
	octave-audio|octave-symbolic|octave-vrml)
		if [ "$PIUPARTS_DISTRIBUTION" = "lenny" ]; then
			USED_DURING_PURGE="$USED_DURING_PURGE octave3.0"
		fi
		;;
	ttf-beteckna)
		#502707
		if [ "$PIUPARTS_DISTRIBUTION" = "lenny" ]; then
			USED_DURING_PURGE="$USED_DURING_PURGE defoma"
		fi
		;;
esac

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