Dodatni upgrade paketa, izmjene u funkcionalnosti.
[mod-security-cn.git] / debian / prerm
1 #!/bin/sh
2
3 set -e
4
5 # chk_conf_tag ()
6 #
7 #   Check if configuration file has CARNet package info lines.
8 #   return:  $RET => 0 - tagged
9 #                    1 - file does not exists
10 #                    2 - file exists, but it is not tagged
11 #
12 chk_conf_tag () {
13
14         local conf_file
15         conf_file="$1"
16         RET=1
17
18         if [ -f "$conf_file" ]; then
19             if egrep -q "^## Begin - Generated by CARNet package mod-security-cn$" "$conf_file"; then
20                 RET=0
21             else
22                 RET=2
23             fi
24         fi
25 }
26
27
28 case "$1" in
29     remove|deconfigure)
30
31         # Include CARNet functions.
32         . /usr/share/carnet-tools/functions.sh
33
34         PKG="mod-security-cn"
35         A2DIR="/etc/apache2"
36         CONFDIR="$A2DIR/conf.d"
37         MODSECDIR="$A2DIR/mod-security"
38         MODSECCONF="$MODSECDIR/mod-security-cn.conf"
39         MODSECRBL="$MODSECDIR/rbl_lookup.conf"
40         MODSECLNK="$CONFDIR/$(basename $MODSECCONF)"
41
42         need_restart=0
43
44
45         # Disable ModSecurity configuration.
46         chk_conf_tag "$MODSECCONF"
47         if [ $RET -eq 0 ]; then
48             if [ -e "$MODSECLNK" ]; then
49                 cp_echo "CN: Disabling ModSecurity configuration."
50                 rm -f "$MODSECLNK"
51                 need_restart=1
52             fi
53         fi
54
55         # Remove configuration files generated by this CARNet package.
56         for file in "$MODSECCONF" "$MODSECRBL"; do
57             chk_conf_tag "$file"
58             if [ $RET -eq 0 ]; then
59                 cp_echo "CN: Removing configuration file $file"
60                 rm -f $file
61                 need_restart=1
62             fi
63         fi
64
65         # Restart Apache2 web server.
66         if [ $need_restart -eq 1 ]; then
67             if apache2ctl configtest 2>/dev/null; then
68
69                 # Restart Apache2 web server.
70                 if [ -x "/etc/init.d/apache2" ]; then
71                     if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
72                         invoke-rc.d apache2 restart || true
73                     else
74                         /etc/init.d/apache2 restart || true
75                     fi
76                 fi
77             else
78                 # Something is broken.
79                 cp_echo "CN: Your Apache2 configuration seem to be broken."
80                 cp_echo "CN: Please, check the service configuration!"
81             fi
82         fi
83
84         # Mail root
85         cp_mail "$PKG"
86
87         echo
88         ;;
89     upgrade|failed-upgrade)
90         ;;
91     *)
92         echo "prerm called with unknown argument \$1'" >&2
93         exit 0
94         ;;
95 esac
96
97 exit 0