Imported Debian patch 2.23.05-1
[hcoop/zz_old/debian/webalizer.git] / debian / postinst
diff --git a/debian/postinst b/debian/postinst
new file mode 100644 (file)
index 0000000..4629374
--- /dev/null
@@ -0,0 +1,98 @@
+#!/bin/sh
+# postinst script for webalizer
+#
+# see: dh_installdeb(1)
+
+set -e
+
+# summary of how this script can be called:
+#        * <postinst> `configure' <most-recently-configured-version>
+#        * <old-postinst> `abort-upgrade' <new version>
+#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
+#          <new-version>
+#        * <postinst> `abort-remove'
+#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
+#          <failed-install-package> <version> `removing'
+#          <conflicting-package> <version>
+# for details, see http://www.debian.org/doc/debian-policy/ or
+# the debian-policy package
+#
+
+# bogus - though necessary - rule
+. /usr/share/debconf/confmodule
+db_version 2.0
+
+case "$1" in
+    configure)
+      db_get webalizer/directory || true
+      OUTPUTDIR="$RET"
+      if [ -z "$OUTPUTDIR" ]; then
+       echo "Fatal: No ouptut dir given, not creating webalizer configuration" >&2
+        exit 1;
+      else
+       if [ ! -d $OUTPUTDIR ]; then
+          if mkdir -p $OUTPUTDIR; then
+            echo "$OUTPUTDIR created" >&2
+          else
+            echo "Something went wrong..." >&2
+            exit 1;
+          fi;
+       fi
+      fi
+
+      db_get webalizer/doc_title || true
+      REPORTTITLE="$RET";
+
+      db_get webalizer/logfile || true
+      LOGFILE="$RET";
+
+      db_get webalizer/dnscache || true
+      DNSCACHE="$RET";
+
+      # create conffile if it doesn't exist yet
+      conffile="/etc/webalizer/webalizer.conf"
+      template_gz=/usr/share/doc/webalizer/examples/sample.conf.gz
+      if [ ! -f $conffile ]; then
+       zcat $template_gz > $conffile
+       WEBHOSTNAME=$(hostname)
+       # uncomment the debconf-handled items
+       sed -i \
+         -e "s/^#HostName .*/HostName ${WEBHOSTNAME}/" \
+         -e "s/^#OutputDir /OutputDir /" \
+         -e "s/^#ReportTitle /ReportTitle/" \
+         -e "s/^#LogFile /LogFile /" \
+         $conffile
+      fi
+      
+      # Finally put these variables in /etc/webalizer/webalizer.conf using sed
+      sed -i \
+       -e "s|^OutputDir .*|OutputDir ${OUTPUTDIR}|" \
+       -e "s/^ReportTitle .*/ReportTitle ${REPORTTITLE}/" \
+       -e "s|^LogFile .*|LogFile ${LOGFILE}|" \
+       $conffile
+
+      # Enable DNSCache Option
+      if [ "$DNSCACHE" = "true" ]; then
+        sed -i \
+               -e "s/^#DNSCache /DNSCache /" \
+               -e "s/^#DNSChildren .*/DNSChildren 10/" \
+               $conffile
+      fi
+    ;;
+
+    abort-upgrade|abort-remove|abort-deconfigure)
+
+    ;;
+
+    *)
+        echo "postinst called with unknown argument \`$1'" >&2
+        exit 1
+    ;;
+esac
+
+# dh_installdeb will replace this with shell code automatically
+# generated by other debhelper scripts.
+
+#DEBHELPER#
+
+exit 0