#!/bin/sh

set -e

. /usr/share/debconf/confmodule

db_get photopub/munge_apache_config

if [ "$RET" = "true" ]; then

   FRAGMENT=`tempfile -d /etc/apache`
   if [ $? -ne 0 ]; then
      echo "$0: Can't create temp file, exiting..." >&2
      exit 1
   fi

   HTTPDCONF=`tempfile -d /etc/apache`
   if [ $? -ne 0 ]; then
      echo "$0: Can't create temp file, exiting..." >&2
      exit 1
   fi

   cp -p /etc/apache/httpd.conf $HTTPDCONF # to get the ownership/perms right
   /usr/lib/photopub/utils/mungefile.pl photopub $FRAGMENT \
      < /etc/apache/httpd.conf > $HTTPDCONF
   diff -u $HTTPDCONF /etc/apache/httpd.conf > /etc/photopub/httpd.conf.diff \
      && true

   mv $HTTPDCONF /etc/apache/httpd.conf
   rm $FRAGMENT

   /etc/init.d/apache reload || true
fi

#DEBHELPER#
