#!/bin/sh

set -e

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

if [ -f /etc/php4/apache/php.ini ]; then
    if grep -q "^[[:space:]]*extension[[:space:]]*=[[:space:]]*idn.so" /etc/php4/apache/php.ini; then
	echo "You are removing IDN support for php4, but it is still"
	echo "enabled in your /etc/php4/apache/php.ini."
	echo
	echo "You should remove this line:"
	echo
	echo "extension=idn.so"
	echo
	echo -n "Do you want me to do it now [Y/n] ?"
	read a
	if ! echo $a | grep -iq ^n; then
	    cat /etc/php4/apache/php.ini | grep -v "^[[:space:]]*extension[[:space:]]*=[[:space:]]*idn.so" > /etc/php4/apache/php.ini.idnremove
	    mv /etc/php4/apache/php.ini.idnremove /etc/php4/apache/php.ini
	fi
    fi
fi

if [ -f /etc/php4/cgi/php.ini ]; then
    if grep -q "^[[:space:]]*extension[[:space:]]*=[[:space:]]*idn.so" /etc/php4/cgi/php.ini; then
	echo "You are removing IDN support for php4, but it is still"
	echo "enabled in your /etc/php4/cgi/php.ini."
	echo
	echo "You should remove this line:"
	echo
	echo "extension=idn.so"
	echo
	echo -n "Do you want me to do it now [Y/n] ?"
	read a
	if ! echo $a | grep -iq ^n; then
	    cat /etc/php4/cgi/php.ini | grep -v "^[[:space:]]*extension[[:space:]]*=[[:space:]]*idn.so" > /etc/php4/cgi/php.ini.idnremove
	    mv /etc/php4/cgi/php.ini.idnremove /etc/php4/cgi/php.ini
	fi
    fi
fi

exit 0
