9bd584398aae25b000a34e2582f64709b085fe4d
[fail2ban-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 CONF=/etc/fail2ban/jail.conf
34
35 if [ -e "$CONF" ]; then
36     # enable ssh and pam-generic services
37     perl -ne 'if (/\[(ssh|pam-generic)\]/ .. /enabled/) { $_ =~ s/enabled = false/enabled = true/gi }; print $_' "$CONF" > "$CONF.$$" && \
38         cp_mv "$CONF.$$" "$CONF"
39     rm -f "$CONF.$$"
40
41     # add network address and class if needed
42     cp_get_netaddr || true
43     NETADDR="$RET"
44     IGNOREIP=$(grep '^ignoreip' "$CONF")
45     if ! echo "$IGNOREIP" | grep -q "$NETADDR"; then
46        cp_check_and_sed '^ignoreip' \
47             "s;^\(ignoreip.*\)$;\1 $NETADDR;g" "$CONF" || true
48     fi
49 fi
50
51 # restart the services
52 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
53         invoke-rc.d fail2ban restart || exit $?
54 else
55         /etc/init.d/fail2ban restart || exit $?
56 fi
57
58 # dh_installdeb will replace this with shell code automatically
59 # generated by other debhelper scripts.
60
61 #DEBHELPER#
62
63 exit 0