6d76d60d39ca064986ee80f9e0f37273495313d7
[webalizer-cn.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
6
7 case "$1" in
8     configure)
9     # continue below
10     ;;
11
12     abort-upgrade|abort-remove|abort-deconfigure)
13     exit 0
14     ;;
15
16     *)
17     echo "postinst called with unknown argument \`$1'" >&2
18     exit 0
19     ;;
20 esac
21
22
23 # Load debconf
24 . /usr/share/debconf/confmodule
25 db_version 2.0
26
27 # Include CARNet functions
28 . /usr/share/carnet-tools/functions.sh
29
30 PKG="webalizer-cn"
31 WDIR="/var/www/webalizer"
32 WHTPASSWD="$WDIR/.htpasswd"
33 WCONF="/etc/webalizer/webalizer.conf"
34 WCONFBAK=`basename $WCONF`
35 oldreporttitle="usage statistics for"
36 reporttitle="Statistika pristupa za"
37
38
39 if [ -f "$WCONF" ]; then
40
41     # Backup first.
42     if cp_check_and_backup "$WCONF"; then
43         cp_echo "CN: Old $WCONF saved as \"/var/backups/$WCONFBAK.bak\"."
44     fi
45
46     # Check for OutputDir
47     temp=`awk 'tolower($1) == "outputdir" { print $2; }' $WCONF | tail -n 1`
48     if [ "$temp" != "$WDIR" ]; then
49         db_set webalizer/directory "$temp" || true
50     fi
51
52     # Check for ReportTitle
53     temp=`awk 'tolower($1) == "reporttitle" { for(i=2; i<NF; i++) \
54           printf("%s ", tolower($i)); print tolower($(NF)) }' $WCONF | tail -n 1`
55     if [ "$temp" = "$oldreporttitle" ]; then
56         temp_re="^[[:space:]]*ReportTitle[[:space:]]*${oldreporttitle}$"
57         cp_check_and_sed "." \
58             "s/$temp_re/ReportTitle     ${reporttitle}/I" \
59             "$WCONF" || true
60         db_set webalizer/doc_title "$reporttitle" || true
61     fi
62 else
63     cp_echo "CN: Configuration file $WCONF is missing."
64 fi
65
66 db_stop || true
67
68
69 # Check Apache2 web server configuration and reload Apache2 web server.
70 #
71 if apache2ctl configtest 2>/dev/null; then
72     invoke-rc.d apache2 force-reload || true
73 else
74     # Something is broken.
75     cp_echo "CN: Your Apache2 configuration is broken."
76     cp_echo "CN: Please, check the service after the installation finishes!"
77 fi
78
79
80 # Generate e-mail message with informations (username and password).
81 #
82 if [ ! -f "$WHTPASSWD" ]; then
83     passwd="$(makepasswd --chars 8)"
84     htpasswd -bcm $WHTPASSWD admin $passwd 2> /dev/null
85     cp_echo ""
86     cp_echo "CN: Webalizer URL is http://`hostname -f`/stats/"
87     cp_echo "CN:            User: admin"
88     cp_echo "CN:        Password: $passwd"
89     cp_echo ""
90     cp_echo "CN: Use \"htpasswd -m $WHTPASSWD admin\" to change it."
91 fi
92
93 # Mail root.
94 #
95 cp_mail "$PKG"
96
97 # dh_installdeb will replace this with shell code automatically
98 # generated by other debhelper scripts.
99
100 #DEBHELPER#
101
102 exit 0