summaryrefslogtreecommitdiffstats
path: root/debian/bind9.preinst
blob: 66b06abaabf1647bcdf7b3526a9b074de0c440b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
# preinst script for bind9
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <new-preinst> `install'
#        * <new-preinst> `install' <old-version>
#        * <new-preinst> `upgrade' <old-version>
#        * <old-preinst> `abort-upgrade' <new-version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
    install|upgrade)
	if [ -n "$2" ] && dpkg --compare-versions "$2" lt "1:9.11.2+dfsg-6"; then
	    theirs=$(md5sum /etc/bind/named.conf.options | sed 's/ .*$//')
	    mine=56919cbc0d819c9a303a8bdeb306b5f1
	    if [ "$mine" = "$theirs" ]; then
		if [ -n "$(dpkg-query -f '${Conffiles}' -W bind9 | grep /etc/bind/named.conf.options)" ]; then
		    # dpkg knows /etc/bind/named.conf.options as a conffile (from squeeze or older)
		    # cannot move the outdated file aside to avoid dpkg noticing deleted-by-local-admin
		    # therefore edit it in place to make it match the to-be-installed version
		    cp -p /etc/bind/named.conf.options /etc/bind/named.conf.options.dpkg-old
		    sed -i '26{/^$/d}; 23{/auth-nxdomain no;/d}' /etc/bind/named.conf.options
		else
		    mv /etc/bind/named.conf.options /etc/bind/named.conf.options.dpkg-old
		fi
	    fi
	fi
    ;;

    abort-upgrade)
	if [ ! -f "/etc/bind/named.conf.options" ] && [ -f "/etc/bind/named.conf.options.dpkg-old" ]; then
	    theirs=$(md5sum /etc/bind/named.conf.options.dpkg-old | sed 's/ .*$//')
	    mine=56919cbc0d819c9a303a8bdeb306b5f1
	    if [ "$mine" = "$theirs" ]; then
		mv /etc/bind/named.conf.options.dpkg-old /etc/bind/named.conf.options
	    fi
	fi
    ;;

    *)
        echo "preinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0