Prva inacica paketa za Debian squeeze distribuciju.
[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     local conf_file
14     conf_file="$1"
15     RET=1
16
17     if [ -f "$conf_file" ]; then
18         if egrep -q "^## Begin - Generated by CARNet package mod-security-cn$" "$conf_file"; then
19             RET=0
20         else
21             RET=2
22         fi
23     fi
24 }
25
26
27 case "$1" in
28     remove|deconfigure)
29
30         # Include CARNet functions.
31         . /usr/share/carnet-tools/functions.sh
32
33         PKG="mod-security-cn"
34         A2DIR="/etc/apache2"
35         CONFDIR="$A2DIR/conf.d"
36         MODSECDIR="$A2DIR/mod-security"
37         MODSECCONF="$MODSECDIR/mod-security-cn.conf"
38         MODSECRBL="$MODSECDIR/rbl_lookup.conf"
39         MODSECLNK="$CONFDIR/$(basename $MODSECCONF)"
40
41         need_restart=0
42
43
44         # Disable ModSecurity configuration.
45         chk_conf_tag "$MODSECCONF"
46         if [ $RET -eq 0 ]; then
47             if [ -e "$MODSECLNK" ]; then
48                 cp_echo "CN: Disabling ModSecurity configuration."
49                 rm -f "$MODSECLNK"
50                 need_restart=1
51             fi
52         fi
53
54         # Remove configuration files generated by this CARNet package.
55         for file in "$MODSECCONF" "$MODSECRBL"; do
56             chk_conf_tag "$file"
57             if [ $RET -eq 0 ]; then
58                 cp_echo "CN: Removing configuration file $file"
59                 rm -f $file
60                 need_restart=1
61             fi
62         done
63
64         # Restart Apache2 web server.
65         if [ $need_restart -eq 1 ]; then
66             if apache2ctl configtest 2>/dev/null; then
67                 invoke-rc.d apache2 force-reload || true
68             else
69                 # Something is broken.
70                 cp_echo "CN: Your Apache2 configuration seem to be broken."
71                 cp_echo "CN: Please, check the service configuration!"
72             fi
73         fi
74
75         # Mail root
76         cp_mail "$PKG"
77
78         echo
79         ;;
80     upgrade|failed-upgrade)
81         ;;
82     *)
83         echo "prerm called with unknown argument \$1'" >&2
84         exit 0
85         ;;
86 esac
87
88 #DEBHELPER#
89
90 exit 0