#!/bin/sh

set -e


if [ "$1" != "configure" ]; then
    exit 0
fi

ask() {
	while : ; do
		echo -n "$1 "
		read a
		[ "$a" = "" ] && a="$2"
		a=`echo $a | tr A-Z a-z`
		[ "$a" = "y" -o "$a" = "n" ] && break
		echo
		echo "Illegal input!"
		echo
	done
}


if [ -n "$2" ]; then
# we're upgrading. don't ask again
        exit 0
fi
	
if [ -f /etc/apache/httpd.conf ]; then 
    if ! grep -qi "^[[:space:]]*LoadModule.*sqlinclude.so" /etc/apache/httpd.conf; then
        echo
	echo "If you want to use this module, you should reconfigure the apache";
	echo "webserver and select to load the sqlinclude module. I can call the";
	echo "apacheconfig script now for you to do it, or you can insert the following"
	echo "line into /etc/apache/httpd.conf manually:";
	echo 
	echo "LoadModule sqlinclude_module /usr/lib/apache/1.3/mod_sqlinclude.so";
	echo
	ask "Do you want me to run the apacheconfig script now [y/N] ?" "n"
	
	if [ "$a" = "y" ] ; then
		[ -x /usr/sbin/apacheconfig ] && /usr/sbin/apacheconfig --force-modules
	else
		echo "Ok, not running apacheconfig. Please read the docs in /usr/share/doc/libapache-mod-sqlinclude"
#		echo -n "Press RETURN to continue"
#		read a;
	fi
    fi
fi

if [ -f /etc/apache-ssl/httpd.conf ]; then 
    if ! grep -qi "^[[:space:]]*LoadModule.*sqlinclude.so" /etc/apache-ssl/httpd.conf; then
        echo
    	echo "If you want to use this module, you should reconfigure the apache-ssl";
	echo "webserver and select to load the sqlinclude module. I can call the";
	echo "apache-sslconfig script now for you to do it, or you can insert the following"
	echo "line into /etc/apache-ssl/httpd.conf manually:";
	echo
	echo "LoadModule sqlinclude_module /usr/lib/apache/1.3/mod_sqlinclude.so";
	echo
	ask "Do you want me to run the apache-sslconfig script now [y/N] ?" "n"
	
	if [ "$a" = "y" ] ; then
		[ -x /usr/sbin/apache-sslconfig ] && /usr/sbin/apache-sslconfig --force-modules
	else
		echo "Ok, not running apache-sslconfig. Please read the docs in /usr/share/doc/libapache-mod-sqlinclude"
#		echo -n "Press RETURN to continue"
#		read a;
	fi
    fi
fi

exit 0


#DEBHELPER#
