Prva inacica paketa za Debian wheezy distribuciju.
[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 customized=0
39 need_restart=0
40
41 if [ -f "$WCONF" ]; then
42
43     # Backup first.
44     if cp_check_and_backup "$WCONF"; then
45         cp_echo "CN: Old $WCONF saved as \"/var/backups/$WCONFBAK.bak\"."
46     fi
47
48     # Check for OutputDir
49     temp=`awk 'tolower($1) == "outputdir" { print $2; }' $WCONF | tail -n 1`
50     if [ "$temp" != "$WDIR" ]; then
51         cp_echo "CN: Found custom OutputDir value: $temp"
52         db_set webalizer/directory "$temp" || true
53         customized=1
54     fi
55
56     # Check for ReportTitle
57     temp=`awk 'tolower($1) == "reporttitle" { for(i=2; i<NF; i++) \
58           printf("%s ", tolower($i)); print tolower($(NF)) }' $WCONF | tail -n 1`
59     if [ "$temp" = "$oldreporttitle" ]; then
60         temp_re="^[[:space:]]*ReportTitle[[:space:]]*${oldreporttitle}$"
61         cp_check_and_sed "." \
62             "s/$temp_re/ReportTitle     ${reporttitle}/I" \
63             "$WCONF" || true
64         db_set webalizer/doc_title "$reporttitle" || true
65         need_restart=1
66     fi
67 else
68     cp_echo "CN: Configuration file $WCONF is missing."
69     customized=1
70 fi
71
72 db_stop || true
73
74
75 # Check Apache2 web server configuration and reload Apache2 web server.
76 #
77 if [ $need_restart -eq 1 ]; then
78     if apache2ctl configtest 2>/dev/null; then
79         invoke-rc.d apache2 force-reload || true
80     else
81         # Something is broken.
82         cp_echo "CN: Your Apache2 configuration is broken."
83         cp_echo "CN: Please, check the service after the installation finishes!"
84     fi
85 fi
86
87
88 # Generate e-mail message with informations (username and password).
89 #
90 if [ $customized -eq 0 ]; then
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     else
101         cp_echo "CN: File $WHTPASSWD already exists."
102     fi
103 else
104     cp_echo "CN: Skipping file $WHTPASSWD"
105 fi
106
107 # Mail root.
108 #
109 cp_mail "$PKG"
110
111 # dh_installdeb will replace this with shell code automatically
112 # generated by other debhelper scripts.
113
114 #DEBHELPER#
115
116 exit 0