#!/bin/sh

set -e



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

if [ -f /etc/apache/httpd.conf ]; then 
    if grep -qi "^LoadModule.*sqlinclude.so" /etc/apache/httpd.conf; then
        echo
	echo "The apache webserver is configured to load the SQLIinclude module at startup"
	echo "If you remove this package now, apache will not start.";
	echo "You should remove all the SQLInclude commands from you apache config";
	echo "and disable it by either removing or commenting out the following lines";
	echo "from httpd.conf:"
	echo
	grep "^LoadModule.*sqlinclude.so" /etc/apache/httpd.conf || true
	echo
	echo -n "Do you want me to remove these lines for you [Y/n] ?"
	read a;
	if ! echo $a | grep -iq ^n; then
		sed -e 's+^LoadModule.*sqlinclude.so+\#LoadModule sqlinclude_module /usr/lib/apache/1.3/mod_sqlinclude.so+' </etc/apache/httpd.conf >/etc/apache/httpd.conf.sqlincluderemove
		mv /etc/apache/httpd.conf.sqlincluderemove /etc/apache/httpd.conf
	else
		echo -n "Do you want to remove this package anyway [y/N] ?"
		read a;
		if echo $a | grep -iq ^y; then
			echo
			echo "Ok, removing package, don't forget to remove the above mentioned"
			echo "lines from /etc/apache/httpd.conf and other SQLInclude commands"
			echo
			echo -n "Press RETURN to continue"
			read a
		else
			exit 1
		fi
	fi
    fi
fi

if [ -f /etc/apache-ssl/httpd.conf ]; then 
    if grep -qi "^LoadModule.*sqlinclude.so" /etc/apache-ssl/httpd.conf; then
        echo
	echo "The apache webserver is configured to load the SQLInclude module at startup"
	echo "If you remove this package now, apache will not start";
	echo "You should remove all the SQLInclude commands from you apache config";
	echo "and disable it by either removing or commenting out the following lines";
	echo "from httpd.conf:"
	echo
	grep "^LoadModule.*sqlinclude.so" /etc/apache-ssl/httpd.conf || true
	echo
	echo -n "Do you want me to remove these lines for you [Y/n] ?"
	read a;
	if ! echo $a | grep -iq ^n; then
		sed -e 's+^LoadModule.*sqlinclude.so+\#LoadModule sqlinclude_module /usr/lib/apache/1.3/mod_sqlinclude.so+' </etc/apache-ssl/httpd.conf >/etc/apache-ssl/httpd.conf.sqlincluderemove
		mv /etc/apache-ssl/httpd.conf.sqlincluderemove /etc/apache-ssl/httpd.conf
	else
		echo -n "Do you want to remove this package anyway [y/N] ?"
		read a;
		if echo $a | grep -iq ^y; then
			echo
			echo "Ok, removing package, don't forget to remove the above mentioned"
			echo "lines from /etc/apache-ssl/httpd.conf and other SQLInclude commands!"
			echo
			echo -n "Press RETURN to continue"
			read a
		else
			exit 1
		fi
	fi
    fi
fi

exit 0

#DEBHELPER#
