Prva verzija za buster.
[webalizer-cn.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
6 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
7
8 # Load Debconf
9 . /usr/share/debconf/confmodule
10 db_version 2.0
11
12 # Include CARNet Tools
13 . /usr/share/carnet-tools/functions.sh
14
15 PKG="webalizer-cn"
16 WDIR="/var/www/webalizer"
17 WHTPASSWD="$WDIR/.htpasswd"
18 WCONF="/etc/webalizer/webalizer.conf"
19 WCONFBAK=`basename $WCONF`
20
21 oldreporttitle="usage statistics for"
22 reporttitle="Statistika pristupa za"
23 customized=0
24
25
26 if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then
27   . /usr/share/apache2/apache2-maintscript-helper
28
29   webalizer_enable() {
30     cp_echo "CN: Enabling $PKG configuration for Apache2."
31     return 0
32   }
33 else
34   cp_echo "CN: Could not load Apache 2.4 maintainer script helper."
35
36   webalizer_enable() {
37     return 1
38   }
39 fi
40
41 webalizer_error() {
42   cp_echo "CN: Error while trying to enable $PKG configuration for Apache2."
43 }
44
45 mv_conffile()
46 {
47   local oldconffile="$1"
48   local newconffile="$2"
49
50   rm -f $oldconffile.dpkg-remove
51   [ -e "$oldconffile" ] || return 0
52
53   cp_echo "CN: Preserving user changes to $newconffile (renamed from $oldconffile)."
54   mv -f "$newconffile" "$newconffile.dpkg-new"
55   mv -f "$oldconffile" "$newconffile"
56 }
57
58
59 mv_conffile /etc/apache2/conf.d/$PKG.conf /etc/apache2/conf-available/$PKG.conf
60
61 if [ -f "$WCONF" ]; then
62   # Backup first.
63   if cp_check_and_backup "$WCONF"; then
64     cp_echo "CN: Old $WCONF saved as /var/backups/$WCONFBAK.bak."
65   fi
66
67   # Check for OutputDir
68   temp=`awk 'tolower($1) == "outputdir" { print $2; }' $WCONF | tail -n 1`
69   if [ "$temp" != "$WDIR" ]; then
70     cp_echo "CN: Found custom OutputDir value: $temp"
71     db_set webalizer/directory "$temp" || true
72     customized=1
73   fi
74
75   # Check for ReportTitle
76   temp=`awk 'tolower($1) == "reporttitle" { for(i=2; i<NF; i++) \
77         printf("%s ", tolower($i)); print tolower($(NF)) }' $WCONF | tail -n 1`
78   if [ "$temp" = "$oldreporttitle" ]; then
79     temp_re="^[[:space:]]*ReportTitle[[:space:]]*${oldreporttitle}$"
80     cp_check_and_sed "." \
81                      "s/$temp_re/ReportTitle    ${reporttitle}/I" \
82                      "$WCONF" || true
83     db_set webalizer/doc_title "$reporttitle" || true
84   fi
85 else
86   cp_echo "CN: Configuration file $WCONF is missing."
87   customized=1
88 fi
89
90 db_stop || true
91
92
93 # Generate e-mail message with informations (username and password).
94 #
95 if [ $customized -eq 0 ]; then
96   if [ ! -f "$WHTPASSWD" ]; then
97     passwd="$(makepasswd --chars 8)"
98     htpasswd -bcm $WHTPASSWD admin $passwd 2> /dev/null
99     cp_echo ""
100     cp_echo "CN: Webalizer URL is http://`hostname -f`/stats/"
101     cp_echo "CN:            User: admin"
102     cp_echo "CN:        Password: $passwd"
103     cp_echo ""
104     cp_echo "CN: Use \"htpasswd -m $WHTPASSWD admin\" to change it."
105   else
106     cp_echo "CN: File $WHTPASSWD already exists."
107   fi
108 else
109   cp_echo "CN: Skipping file $WHTPASSWD"
110 fi
111
112 #DEBHELPER#
113
114 if ! apache2ctl configtest >/dev/null 2>&1; then
115   cp_echo "CN: Your Apache2 configuration seems to be broken."
116   cp_echo "CN: Please, check the service after the installation finishes!"
117 fi
118
119 # Mail root.
120 #
121 cp_mail "$PKG"
122
123 exit 0