#!/bin/sh

set -e

PECL_NAME=idn

if [ "$1" != "remove" -a "$1" != "purge" ]; then
	exit 0
fi

EXTENSIONRE="^[[:space:]]*extension[[:space:]]*=[[:space:]]*${PECL_NAME}.so"

. /usr/share/debconf/confmodule

if [ "$DPKG_DEBUG" = "developer" ]; then
  set -x
fi

for SAPI in `find /etc/php4/ -type d -maxdepth 1 -mindepth 1 | sed -e's#.*/##'`
do
	# Use the same question for all extensions, because it's only
	# used once per package: right here.
	if [ -f "/etc/php4/$SAPI/php.ini" ] \
	   && grep -q "$EXTENSIONRE" /etc/php4/$SAPI/php.ini
	then
		db_set php4/remove_extension true
		db_title "PHP"
		db_subst php4/remove_extension extname ${PECL_NAME}
		db_subst php4/remove_extension sapiconfig $SAPI
		db_input low php4/remove_extension || true
		db_go

		db_get php4/remove_extension
		if [ "$RET" = "true" ]; then
			grep -v "$EXTENSIONRE" < /etc/php4/$SAPI/php.ini \
				> /etc/php4/$SAPI/php.ini.${PECL_NAME}remove
			chmod --reference=/etc/php4/$SAPI/php.ini \
				/etc/php4/$SAPI/php.ini.${PECL_NAME}remove
			mv /etc/php4/$SAPI/php.ini.${PECL_NAME}remove \
				/etc/php4/$SAPI/php.ini
		fi
		db_fset php4/remove_extension seen false
	fi
done

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
