#!/bin/sh -e
# Only remove database if niether debconf nor debconf-tiny are installed.
if [ "$1" = "purge" -a \
     ! -e /usr/share/doc/debconf/copyright -a \
     ! -e /usr/share/doc/debconf-tiny/copyright ]; then
	rm -f /var/lib/debconf/debconf.db /var/lib/debconf/templates.db
fi
if [ -e /etc/apt/apt.conf ]; then
	cp /etc/apt/apt.conf /etc/apt/apt.conf.old
	(grep -iv "// Pre-configure all packages" /etc/apt/apt.conf.old | \
		grep -iv "// (Automatically added by debconf.)" | \
		grep -iv dpkg-preconfigure > /etc/apt/apt.conf) || true
	rm -f /etc/apt/apt.conf.old
	if [ ! -s /etc/apt/apt.conf ]; then
		rm -f /etc/apt/apt.conf
		rmdir --ignore-fail-on-non-empty -p /etc/apt/
	fi
fi

