r3: - more compatible with mawk
[ossec-hids-cn.git] / debian / postinst
1 #!/bin/sh
2 # postinst script for bind9-cn
3 #
4 # see: dh_installdeb(1)
5
6 set -e
7
8 # summary of how this script can be called:
9 #        * <postinst> `configure' <most-recently-configured-version>
10 #        * <old-postinst> `abort-upgrade' <new version>
11 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
12 #          <new-version>
13 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
14 #          <failed-install-package> <version> `removing'
15 #          <conflicting-package> <version>
16 # for details, see http://www.debian.org/doc/debian-policy/ or
17 # the debian-policy package
18 #
19
20 case "$1" in
21     configure|reconfigure)
22       # continue below
23     ;;
24
25     *)
26         exit 0
27     ;;
28 esac
29
30 # import CN-functions
31 . /usr/share/carnet-tools/functions.sh
32
33 # get installation directory
34 . /etc/ossec-init.conf
35 if [ "X${DIRECTORY}" = "X" ]; then
36     DIRECTORY="/var/ossec"
37 fi
38
39 # sanity check
40 if [ ! -d "$DIRECTORY/rules" ]; then
41     echo "CN: There is no "$DIRECTORY/rules" directory, exiting..."
42     echo "CN: Please reinstall ossec-hids package"
43     exit 1
44 fi
45
46 # find first available sid
47 local_rules="$DIRECTORY/rules/local_rules.xml"
48 script='
49 BEGIN {
50     FS = "\""
51 }
52 /<rule id="[0-9]*".*>/ {
53     if (max < $2)
54         max = $2
55 }
56 END {
57     print max
58 };
59 '
60 if [ -e "$local_rules" ]; then
61     sid=$(awk "$script" "$local_rules")
62 fi
63 if [ -z "$sid" ]; then
64     sid=100000
65 fi
66
67 # update local rules with our policy
68 if [ -e "$local_rules" ]; then
69     cp "$local_rules" "$local_rules.$$"
70 else
71     touch "$local_rules.$$"
72 fi
73
74 cp-update --comment '<!--' --comment-end '-->' \
75     ossec-hids-cn "$local_rules.$$" <<EOF
76 <group name="syslog,errors,local">
77  <rule id="$(expr "$sid" + 1)" level="0">
78    <if_sid>1002</if_sid>
79    <match>rsync</match>
80    <description>Events ignored</description>
81  </rule>
82
83  <rule id="$(expr "$sid" + 2)" level="0">
84    <if_sid>1002</if_sid>
85    <program_name>^sophie|^smartd</program_name>
86    <description>Events ignored</description>
87  </rule>
88 </group>
89
90 <group name="syslog,postfix,local">
91  <rule id="$(expr "$sid" + 3)" level="0">
92    <if_sid>3303</if_sid>
93    <description>Events ignored</description>
94  </rule>
95
96  <rule id="$(expr "$sid" + 4)" level="0">
97   <if_sid>3356</if_sid>
98   <description>Ignore blacklisted mail</description>
99  </rule>
100 </group>
101 EOF
102 cp_mv "$local_rules.$$" "$local_rules"
103
104 # and restart the service
105 if [ -x /usr/sbin/invoke-rc.d ]; then
106     invoke-rc.d ossec-hids restart
107 else
108     /etc/init.d/ossec-hids restart
109 fi
110
111 # dh_installdeb will replace this with shell code automatically
112 # generated by other debhelper scripts.
113
114 #DEBHELPER#
115
116 exit 0