| 1 | #!/bin/sh |
| 2 | # postinst script for webalizer |
| 3 | # |
| 4 | # see: dh_installdeb(1) |
| 5 | |
| 6 | set -e |
| 7 | |
| 8 | # summary of how this script can be called: |
| 9 | # * <postinst> `configure' <most-recently-configured-version> |
| 10 | # * <old-postinst> `abort-upgrade' <new version> |
| 11 | # * <conflictor's-postinst> `abort-remove' `in-favour' <package> |
| 12 | # <new-version> |
| 13 | # * <postinst> `abort-remove' |
| 14 | # * <deconfigured's-postinst> `abort-deconfigure' `in-favour' |
| 15 | # <failed-install-package> <version> `removing' |
| 16 | # <conflicting-package> <version> |
| 17 | # for details, see http://www.debian.org/doc/debian-policy/ or |
| 18 | # the debian-policy package |
| 19 | # |
| 20 | |
| 21 | # bogus - though necessary - rule |
| 22 | . /usr/share/debconf/confmodule |
| 23 | db_version 2.0 |
| 24 | |
| 25 | case "$1" in |
| 26 | configure) |
| 27 | db_get webalizer/directory || true |
| 28 | OUTPUTDIR="$RET" |
| 29 | if [ -z "$OUTPUTDIR" ]; then |
| 30 | echo "Fatal: No ouptut dir given, not creating webalizer configuration" >&2 |
| 31 | exit 1; |
| 32 | else |
| 33 | if [ ! -d $OUTPUTDIR ]; then |
| 34 | if mkdir -p $OUTPUTDIR; then |
| 35 | echo "$OUTPUTDIR created" >&2 |
| 36 | else |
| 37 | echo "Something went wrong..." >&2 |
| 38 | exit 1; |
| 39 | fi; |
| 40 | fi |
| 41 | fi |
| 42 | |
| 43 | db_get webalizer/doc_title || true |
| 44 | REPORTTITLE="$RET"; |
| 45 | |
| 46 | db_get webalizer/logfile || true |
| 47 | LOGFILE="$RET"; |
| 48 | |
| 49 | db_get webalizer/dnscache || true |
| 50 | DNSCACHE="$RET"; |
| 51 | |
| 52 | # create conffile if it doesn't exist yet |
| 53 | conffile="/etc/webalizer/webalizer.conf" |
| 54 | template_gz=/usr/share/doc/webalizer/examples/sample.conf.gz |
| 55 | if [ ! -f $conffile ]; then |
| 56 | zcat $template_gz > $conffile |
| 57 | WEBHOSTNAME=$(hostname) |
| 58 | # uncomment the debconf-handled items |
| 59 | sed -i \ |
| 60 | -e "s/^#HostName .*/HostName ${WEBHOSTNAME}/" \ |
| 61 | -e "s/^#OutputDir /OutputDir /" \ |
| 62 | -e "s/^#ReportTitle /ReportTitle/" \ |
| 63 | -e "s/^#LogFile /LogFile /" \ |
| 64 | $conffile |
| 65 | fi |
| 66 | |
| 67 | # Finally put these variables in /etc/webalizer/webalizer.conf using sed |
| 68 | sed -i \ |
| 69 | -e "s|^OutputDir .*|OutputDir ${OUTPUTDIR}|" \ |
| 70 | -e "s/^ReportTitle .*/ReportTitle ${REPORTTITLE}/" \ |
| 71 | -e "s|^LogFile .*|LogFile ${LOGFILE}|" \ |
| 72 | $conffile |
| 73 | |
| 74 | # Enable DNSCache Option |
| 75 | if [ "$DNSCACHE" = "true" ]; then |
| 76 | sed -i \ |
| 77 | -e "s/^#DNSCache /DNSCache /" \ |
| 78 | -e "s/^#DNSChildren .*/DNSChildren 10/" \ |
| 79 | $conffile |
| 80 | fi |
| 81 | ;; |
| 82 | |
| 83 | abort-upgrade|abort-remove|abort-deconfigure) |
| 84 | |
| 85 | ;; |
| 86 | |
| 87 | *) |
| 88 | echo "postinst called with unknown argument \`$1'" >&2 |
| 89 | exit 1 |
| 90 | ;; |
| 91 | esac |
| 92 | |
| 93 | # dh_installdeb will replace this with shell code automatically |
| 94 | # generated by other debhelper scripts. |
| 95 | |
| 96 | #DEBHELPER# |
| 97 | |
| 98 | exit 0 |