#!/bin/sh
set -e

log_debug() {
	echo "Debug: piuparts exception for package $PIUPARTS_OBJECTS"
}

#
# deal with packages depending on exceptions:
#
case ${PIUPARTS_OBJECTS%%=*} in
	ltsp-client)		log_debug
				PIUPARTS_OBJECTS=ltsp-client-core
				;;
esac

#
# deal with exceptions:
#
case ${PIUPARTS_OBJECTS%%=*} in
	fai-nfsroot)		log_debug
				rm -f /.THIS_IS_THE_FAI_NFSROOT
				;;
	ltsp-client-core)	log_debug
				rm -f /etc/ltsp_chroot
				;;
	file-rc)		log_debug
				# removal wont work if sysv-rc isn't reinstalled
				yes 'Yes, do as I say!' | apt-get -y --force-yes install sysv-rc
				dpkg --purge file-rc
				;;
	amd64-libs|amd64-libs-dev)
		# leaves a superfluous empty line after purge
		log_debug
		sed -i '3{/^$/d}' /etc/ld.so.conf
		;;
	localepurge)
		case ${PIUPARTS_DISTRIBUTION} in
			lenny*|squeeze*) ;;
			*)
				# reinstall packages where files might have been dropped
				log_debug
				EXTRA="base-passwd"
				apt-get -u --reinstall --fix-missing install $(dpkg -S LC_MESSAGES | cut -d: -f1 | tr ', ' '\n' | sort -u) $EXTRA
				;;
		esac
		;;
	gdm3|gnome-session|gnome-shell*|gnome-core|gnome|gnome-desktop-environment|task-gnome-desktop|razorqt|sucrose-0.96|xfswitch-plugin|mate-core|mate-desktop-environment*|task-kde-desktop|kde-standard|kde-plasma-desktop|kde-plasma-netbook|ltsp-server-standalone)
		# see pre_remove_exceptions for why this is needed
		log_debug
		case ${PIUPARTS_DISTRIBUTION} in
			lenny*|squeeze*|wheezy)
				echo "PIUPARTS_DISTRIBUTION=$PIUPARTS_DISTRIBUTION, not applying systemd-sysv removal workaround"
				;;
			*)
				dpkg --purge systemd-shim
				;;
		esac
		;;
esac
