#!/bin/bash
set -e

# DJ: function to comment us out in httpd.conf
killconf () {
	    apacheconf=/etc/${apache}/httpd.conf
        if test -s $apacheconf
        then
          if grep -q "^[[:space:]]*<IfModule mod_gzip.c>" $apacheconf; then
              perl -00 -p -i -e "s:\s*<IfModule mod_gzip.c>\n\s*# The current block will be removed automatically by prerm script(.*\n)+\s*</IfModule>\n?::" $apacheconf
          fi
          if grep -q "^[[:space:]]*mod_gzip" $apacheconf
	      then
	        perl -p -i -e "s/^(\s*mod_gzip.*)/# \1/" $apacheconf
	      fi
          if grep -q "^[[:space:]]*\(Custom\|Transfer\)Log[[:space:]]\+.*mod_gzip_info" $apacheconf
		  then
		    perl -p -i -e "s/^(\s*(Custom|Transfer)Log\s+.*mod_gzip_info)/# \1/" $apacheconf
		  fi

          test ! -x /usr/sbin/${apache} || modules-config ${apache} disable mod_gzip
          ask_restart
        fi
}

# Restart apache if user wants.
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/${apache}ctl ]; then
                /usr/sbin/${apache}ctl restart || true
           else
               echo "${apache}ctl not found."
           fi
        fi
}


case "$1" in
  remove)
    # This package has been removed, but its configuration has not yet
    # been purged.
      for apache in apache apache-ssl apache-perl
	  do
           killconf
      done
    :
    ;;
  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

#DEBHELPER#

exit 0

