a3b3604b7990cdfbc997b3c1ea52f3c09177b69e
[webalizer-cn.git] / debian / postinst
1 #!/bin/sh
2
3 [ "$1" = "configure" ] || exit 0
4 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -x
5
6 # Load CARNet Tools
7 . /usr/share/carnet-tools/functions.sh
8
9 # Debconf
10 . /usr/share/debconf/confmodule
11
12 # Get some useful functions (apache-common)
13 . /usr/share/apache/postinst.common
14
15 dir=/var/www/webalizer
16 htpasswd=$dir/.htpasswd
17 CONF=/etc/webalizer/webalizer.conf
18 BACKUPDIR=/var/backups
19 CONFBAK=$BACKUPDIR/`basename $CONF`.bak
20 oldreporttitle="Usage Statistics for"
21 reporttitle="Statistika pristupa za"
22
23
24 # Check if there is some old webalizer-cn.conf file in Apache 1.x conf.d directory  -ddosen
25 if [ -f "/etc/apache/conf.d/webalizer-cn.conf" ]; then
26         if ! cmp -s "/etc/apache/conf.d/webalizer-cn.conf" "/etc/apache2/conf.d/webalizer-cn.conf"; then
27                 mv /etc/apache/conf.d/webalizer-cn.conf /etc/apache2/conf.d/webalizer-cn.conf
28         fi
29 fi
30
31 temp=`pget $CONF OutputDir |tail -n 1|awk '{print $NF}'`
32 if [ "$temp" != "$dir" ]; then
33         #cp_echo "CN: Found custom OutputDir value: $temp, not touching anything!"
34         db_set webalizer/directory "$temp" || true
35 fi
36
37 # Customise ReportTitle
38 temp=`pget $CONF ReportTitle |tail -n 1|perl -pe 's/(ReportTitle\s+?)(.*$)/$2/'`
39 if [ "$temp" = "$oldreporttitle" ]; then
40         pset $CONF ReportTitle "$reporttitle"
41         db_set webalizer/doc_title "$reporttitle" || true
42 fi
43
44 db_stop
45
46 # Reload Apache2 web server
47 if [ -x /etc/init.d/apache2 ]; then
48         /etc/init.d/apache2 reload || true
49 fi
50
51 # Send mail with informations
52 if [ ! -f $htpasswd ]; then
53         passwd=`makepasswd`
54         htpasswd -bc $htpasswd admin $passwd 2> /dev/null
55         cp_echo ""
56         cp_echo "CN: Webalizer URL is http://`hostname -f`/stats/"
57         cp_echo "CN:            User: admin"
58         cp_echo "CN:        Password: $passwd"
59         cp_echo ""
60         cp_echo "CN: Use \"htpasswd $htpasswd admin\" to change it."
61         cp_mail "webalizer-cn"
62 fi