#!/bin/bash
# vim: set ts=2 sw=2 et:

set -e

# These functions comment out the LoadModule directive in httpd.conf
# for apache/apache-ssl.  They also ask the user whether to restart
# apache/apache-ssl.
killconf () {
  src=/etc/apache/httpd.conf
  dst=/etc/apache/httpd.conf.tmp.$$
  if [ -s $src ] ; then
    sed 's/^\(LoadModule.*mod_fastcgi\.so\)/# \1/' $src > $dst
    mv -f $dst $src
    ask_restart
  fi
}
killconfssl () {
  src=/etc/apache-ssl/httpd.conf
  dst=/etc/apache-ssl/httpd.conf.tmp.$$
  if [ -s $src ] ; then
    sed 's/^\(LoadModule.*mod_fastcgi\.so\)/# \1/' $src > $dst
    mv -f $src $dst
    ask_restartssl
  fi
}

# These functions ask the user whether to restart apache/apachessl.
ask_restart () {
  echo -n "An Apache module has been modified.  Restart apache [Y/n]? "
  read CONFIG
  if [ ".$CONFIG" != ".n" -a ".$CONFIG" != ".N" ]
  then
    if [ -x /usr/sbin/apachectl ]; then
      /usr/sbin/apachectl restart || true
    else
      echo 'apachectl not found.'
    fi
  fi
}
ask_restartssl () {
  echo -n "An Apache module has been modified.  Restart apache-ssl [Y/n]? "
  read CONFIG
  if [ ".$CONFIG" != ".n" -a ".$CONFIG" != ".N" ] ; then
    if [ -x /usr/sbin/apache-sslctl ]; then
      /usr/sbin/apache-sslctl restart || true
    else
      echo 'apache-sslctl not found.'
    fi
  fi
}        

# This script is called twice during the removal of the package; once
# after the removal of the package's files from the system, and as
# the final step in the removal of this package, after the package's
# conffiles have been removed.

case "$1" in
  remove)
    # This package has been removed, but its configuration has not yet
    # been purged.
    killconf
    killconfssl
    :
    ;;
  upgrade | deconfigure | failed-upgrade)
    # I _think_ I'm right here...let it sit on an upgrade.
    :
    ;;
  *)
    echo "$0: didn't understand being called with \`$1'" 1>&2
    exit 1
    ;;
esac

exit 0

#DEBHELPER#
