- lintian fixevi
[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, pam-generic, sasl, proftpd and vsftpd service
37     perl -ne 'if (/\[(ssh|pam-generic|sasl|proftpd|vsftpd)\]/ .. /enabled/) { $_ =~ s/enabled = false/enabled = true/gi }; print $_' "$CONF" > "$CONF.$$" && \
38         cp_mv "$CONF.$$" "$CONF"
39     rm -f "$CONF.$$"
40
41     # enable dovecot service
42     cp-update fail2ban-cn "$CONF.$$" <<EOF
43 [dovecot]
44
45 enabled     = true
46 port        = 110,143
47 protocol    = tcp
48 filter      = dovecot
49 logpath     = /var/log/mail.log
50 EOF
51     cp_mv "$CONF.$$" "$CONF"
52
53     # add network address and class if needed
54     cp_get_netaddr || true
55     NETADDR="$RET"
56     IGNOREIP=$(grep '^ignoreip' "$CONF")
57     if ! echo "$IGNOREIP" | grep -q "$NETADDR"; then
58        cp_check_and_sed '^ignoreip' \
59             "s;^\(ignoreip.*\)$;\1 $NETADDR;g" "$CONF" || true
60     fi
61 fi
62
63 # restart the services
64 if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
65         invoke-rc.d fail2ban restart || exit $?
66 else
67         /etc/init.d/fail2ban restart || exit $?
68 fi
69
70 # dh_installdeb will replace this with shell code automatically
71 # generated by other debhelper scripts.
72
73 #DEBHELPER#
74
75 exit 0