Prva verzija za buster.
[mod-security-cn.git] / debian / prerm
1 #!/bin/sh
2
3 set -e
4
5 PKG=mod-security-cn
6
7 MODSECCONF=/etc/apache2/mod-security/$PKG.conf
8 MODSECRBL=/etc/apache2/mod-security/rbl_lookup.conf
9 MODSECLNK=/etc/apache2/conf-available/security2-cn.conf
10
11 # chk_conf_tag ()
12 #
13 #   Check if configuration file has CARNet package info lines.
14 #   return:  $RET => 0 - tagged
15 #                    1 - file does not exists
16 #                    2 - file exists, but it is not tagged
17 #
18 chk_conf_tag () {
19   local conf_file
20   conf_file="$1"
21   RET=1
22
23   if [ -f "$conf_file" ]; then
24     if egrep -q "^## Begin - Generated by CARNet package mod-security-cn$" "$conf_file"; then
25       RET=0
26     else
27       RET=2
28     fi
29   fi
30 }
31
32 if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then
33   . /usr/share/apache2/apache2-maintscript-helper
34
35   modsecurity_enable() {
36     chk_conf_tag "$MODSECLNK"
37     if [ $RET -ne 2 ]; then
38       echo "CN: Disabling $PKG configuration for Apache2."
39       return 0
40     fi
41     return 1
42   }
43 else
44   echo "CN: Could not load Apache 2.4 maintainer script helper."
45
46   modsecurity_enable() {
47     return 1
48   }
49 fi
50
51 if [ "$1" = "remove" ] || [ "$1" = "deconfigure" ]; then
52   # Disable ModSecurity configuration.
53   if modsecurity_enable; then
54     apache2_invoke disconf security2-cn
55     rm -f "$MODSECLNK"
56   fi
57
58   # Remove configuration files generated by this CARNet package.
59   for mfile in "$MODSECCONF" "$MODSECRBL"; do
60     chk_conf_tag "$mfile"
61     if [ $RET -eq 0 ]; then
62       echo "CN: Removing configuration file $mfile"
63       rm -f "$mfile"
64     fi
65   done
66 fi
67
68 #DEBHELPER#
69
70 exit 0