Ispravak verzije paketa za Debian lenny.
[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++) printf("%s ", $i); print $(NF) }' $WCONF | tail -n 1`
53         if [ "$temp" = "$oldreporttitle" ]; then
54
55                 temp_re="^[[:space:]]*ReportTitle[[:space:]]*${oldreporttitle}$"
56                 cp_check_and_sed "." \
57                         "s/$temp_re/ReportTitle ${reporttitle}/I" \
58                         "$WCONF" || true
59                 db_set webalizer/doc_title "$reporttitle" || true
60         fi
61 else
62         cp_echo "CN: Configuration file $WCONF is missing."
63 fi
64
65 db_stop || true
66
67
68 # Check Apache2 web server configuration and reload Apache2 web server.
69 #
70 if /usr/sbin/apache2ctl configtest 2>/dev/null; then
71
72         # Reload Apache2 web server.
73         if [ -x "/etc/init.d/apache2" ]; then
74             if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
75                 invoke-rc.d apache2 reload || true
76             else
77                 /etc/init.d/apache2 reload || true
78             fi
79         fi
80 else
81
82         # Something is broken.
83         cp_echo "CN: Your Apache2 configuration is broken."
84         cp_echo "CN: Please, check the service after the installation finishes!"
85 fi
86
87
88 # Generate e-mail message with informations (username and password).
89 #
90 if [ ! -f "$WHTPASSWD" ]; then
91         passwd=`makepasswd --chars 8`
92         htpasswd -bcm $WHTPASSWD admin $passwd 2> /dev/null
93         cp_echo ""
94         cp_echo "CN: Webalizer URL is http://`hostname -f`/stats/"
95         cp_echo "CN:            User: admin"
96         cp_echo "CN:        Password: $passwd"
97         cp_echo ""
98         cp_echo "CN: Use \"htpasswd -m $WHTPASSWD admin\" to change it."
99 fi
100
101
102 # Mail root.
103 #
104 cp_mail "$PKG"
105
106 exit 0