+#!/bin/sh
+
+[ "$1" = "configure" ] || exit 0
+[ "$DEBIAN_SCRIPT_DEBUG" ] && set -x
+
+# Load CARNet Tools
+. /usr/share/carnet-tools/functions.sh
+
+# Debconf
+. /usr/share/debconf/confmodule
+
+# Get some useful functions (apache-common)
+. /usr/share/apache/postinst.common
+
+dir=/var/www/webalizer
+htpasswd=$dir/.htpasswd
+CONF=/etc/webalizer/webalizer.conf
+BACKUPDIR=/var/backups
+CONFBAK=$BACKUPDIR/`basename $CONF`.bak
+oldreporttitle="Usage Statistics for"
+reporttitle="Statistika pristupa za"
+
+
+# Check if there is some old webalizer-cn.conf file in Apache 1.x conf.d directory -ddosen
+if [ -f "/etc/apache/conf.d/webalizer-cn.conf" ]; then
+ if ! cmp -s "/etc/apache/conf.d/webalizer-cn.conf" "/etc/apache2/conf.d/webalizer-cn.conf"; then
+ mv /etc/apache/conf.d/webalizer-cn.conf /etc/apache2/conf.d/webalizer-cn.conf
+ fi
+fi
+
+temp=`pget $CONF OutputDir |tail -n 1|awk '{print $NF}'`
+if [ "$temp" != "$dir" ]; then
+ #cp_echo "CN: Found custom OutputDir value: $temp, not touching anything!"
+ db_set webalizer/directory "$temp" || true
+fi
+
+# Customise ReportTitle
+temp=`pget $CONF ReportTitle |tail -n 1|perl -pe 's/(ReportTitle\s+?)(.*$)/$2/'`
+if [ "$temp" = "$oldreporttitle" ]; then
+ pset $CONF ReportTitle "$reporttitle"
+ db_set webalizer/doc_title "$reporttitle" || true
+fi
+
+db_stop
+
+# Reload Apache2 web server
+if [ -x /etc/init.d/apache2 ]; then
+ /etc/init.d/apache2 reload || true
+fi
+
+# Send mail with informations
+if [ ! -f $htpasswd ]; then
+ passwd=`makepasswd`
+ htpasswd -bc $htpasswd admin $passwd 2> /dev/null
+ cp_echo ""
+ cp_echo "CN: Webalizer URL is http://`hostname -f`/stats/"
+ cp_echo "CN: User: admin"
+ cp_echo "CN: Password: $passwd"
+ cp_echo ""
+ cp_echo "CN: Use \"htpasswd $htpasswd admin\" to change it."
+ cp_mail "webalizer-cn"
+fi