c4fca829cebd3e506892dc7f3e88080fd4754fee
[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
26 # Include CARNet functions
27 . /usr/share/carnet-tools/functions.sh
28
29 PKG="webalizer-cn"
30 WDIR="/var/www/webalizer"
31 WHTPASSWD="$WDIR/.htpasswd"
32 WCONF="/etc/webalizer/webalizer.conf"
33 WCONFBAK=`basename $WCONF`
34 oldreporttitle="usage statistics for"
35 reporttitle="Statistika pristupa za"
36
37
38 if [ -f "$WCONF" ]; then
39
40         # Backup first.
41         if cp_check_and_backup "$WCONF"; then
42                 cp_echo "CN: Old $WCONF saved as \"/var/backups/$WCONFBAK.bak\"."
43         fi
44
45         # Check for OutputDir
46         temp=`awk 'tolower($1) == "outputdir" { print $2; }' $WCONF | tail -n 1`
47         if [ "$temp" != "$WDIR" ]; then
48                 db_set webalizer/directory "$temp" || true
49         fi
50
51         # Check for ReportTitle
52         temp=`awk 'tolower($1) == "reporttitle" { for(i=2; i<NF; i++) \
53               printf("%s ", tolower($i)); print tolower($(NF)) }' $WCONF | tail -n 1`
54         if [ "$temp" = "$oldreporttitle" ]; then
55
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 /usr/sbin/apache2ctl configtest 2>/dev/null; then
72
73         # Reload Apache2 web server.
74         if [ -x "/etc/init.d/apache2" ]; then
75             if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
76                 invoke-rc.d apache2 reload || true
77             else
78                 /etc/init.d/apache2 reload || true
79             fi
80         fi
81 else
82
83         # Something is broken.
84         cp_echo "CN: Your Apache2 configuration is broken."
85         cp_echo "CN: Please, check the service after the installation finishes!"
86 fi
87
88
89 # Generate e-mail message with informations (username and password).
90 #
91 if [ ! -f "$WHTPASSWD" ]; then
92         passwd=`makepasswd --chars 8`
93         htpasswd -bcm $WHTPASSWD admin $passwd 2> /dev/null
94         cp_echo ""
95         cp_echo "CN: Webalizer URL is http://`hostname -f`/stats/"
96         cp_echo "CN:            User: admin"
97         cp_echo "CN:        Password: $passwd"
98         cp_echo ""
99         cp_echo "CN: Use \"htpasswd -m $WHTPASSWD admin\" to change it."
100 fi
101
102
103 # Mail root.
104 #
105 cp_mail "$PKG"
106
107 exit 0