r12: - add symlink /etc/init.d/iptables -> /etc/init.d/iptables-cn
[iptables-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 # fix problem with permissions from the old package
31 if dpkg --compare-versions "$2" lt "2:1.2.11-4"; then
32     chown -f -Rh root:root /var/lib/iptables /etc/init.d/iptables \
33                 /etc/default/iptables >/dev/null 2>&1 || true
34 fi
35
36 # remove old iptables init script
37 update-rc.d -f iptables remove >/dev/null 2>&1 || true
38
39 # check if old default file exists and import it
40 if [ -e /etc/default/iptables ]; then
41     mv /etc/default/iptables /etc/default/iptables-cn
42 fi
43
44 # check if there is any default netfilter policy and install default SSH
45 # REJECT recent if there is none..
46 # also, save current set of rules into active and inactive configuration
47 if [ ! -e /var/lib/iptables/active ]; then
48     if ! iptables-save | grep '^-' >/dev/null; then
49         echo "CN: Netfilter rules empty: importing SSH bruteforce rules"
50         . /usr/share/doc/iptables-cn/examples/ssh-bruteforce
51     fi
52     echo "CN: Saving current Netfilter rules to /var/lib/iptables/active"
53     iptables-save > /var/lib/iptables/active
54 fi
55
56 # create inactive
57 if [ ! -e /var/lib/iptables/inactive ]; then
58     touch /var/lib/iptables/inactive
59 fi
60
61 # dh_installdeb will replace this with shell code automatically
62 # generated by other debhelper scripts.
63
64 #DEBHELPER#
65
66 exit 0