summaryrefslogtreecommitdiffstats
path: root/debian/apache2.preinst.in
blob: ebd9fe54a7a163b3c464cf3f87a8d33a328d08c3 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#! /bin/bash
# preinst script for apache2
#
# 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 http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

FIXUP_TEMPFILE=


# During the migration of conffiles from apache2.2-common to apache2,
# some things may have gone wrong.
# * Some conffiles may have been left with obsolete content. These
#   have an md5sum in this list.
# * Some other conffiles may have been removed but dpkg still thinks that
#   they belong to apache2.2-common. A few of these have been re-introduced,
#   but dpkg being confused about their state causes dpkg to think the
#   admin has removed them and to not create the new content.
#   These have a 'restore' instead of a md5 in the list.
list_fixup_conffiles () {
	cat <<- EOF
		/etc/bash_completion.d/apache2					6a5f85e62655f6b5c8fa0f95c7c35c9c	removed
		/etc/apache2/sites-available/000-default.conf			2cc450cf300a880abbc3767fc002477d
		/etc/apache2/sites-available/default-ssl.conf			196d150beeaeaf845ece50d7e84e12de
		/etc/apache2/conf-available/charset.conf			e6fbb8adf631932851d6cc522c1e48d7
		/etc/apache2/conf-available/localized-error-pages.conf		844ba27ddb794fc6967bfb56b950e6a8
		/etc/apache2/conf-available/other-vhosts-access-log.conf	2cad303fc4221d6b0068a8b37597b9fb
		/etc/apache2/conf-available/security.conf			0f644d9d04ad556f44f1e65674bc07dc
		/etc/apache2/mods-available/cern_meta.load			restore
		/etc/apache2/mods-available/ident.load				restore
		/etc/apache2/mods-available/imagemap.load			restore
		EOF
}

create_fixup_conffiles_tgz () {
	FIXUP_TEMPFILE=$(mktemp)
	base64 -d > $FIXUP_TEMPFILE << EOF
XXX_FIXUP_CONFFILES_BASE64_XXX
EOF
}

extract_fixup_conffile () {
	local FILE=$1
	local BASENAME=${FILE##*/}
	tar -xz -O -f $FIXUP_TEMPFILE $BASENAME > $FILE
}

replace_broken_conffiles () {
	local FILE
	local MD5
	create_fixup_conffiles_tgz
	while read FILE MD5 REMOVED ; do
		if [ -f "$FILE" ] && md5sum "$FILE" | grep -q "^$MD5 " ; then
			echo "Replacing broken conffile ${FILE}."
			mv "$FILE" "${FILE}.dpkg-remove-fixup"
			if [ -z "$REMOVED" ] ; then
				extract_fixup_conffile "$FILE"
			fi
		elif [ ! -e "$FILE" ] && [ "$MD5" = "restore" ] ; then
			echo "Restoring lost conffile ${FILE}."
			extract_fixup_conffile "$FILE"
		fi
	done
	rm -f "$FIXUP_TEMPFILE"
}

revert_broken_conffiles () {
	local FILE
	local MD5
	local REMOVE
	while read FILE MD5 REMOVED; do
		if [ -f "$FILE.dpkg-remove-fixup" ]; then
			echo "Moving broken conffile $FILE back."
			mv "${FILE}.dpkg-remove-fixup" "$FILE"
		fi
	done
}

case "$1" in
    upgrade|install)

	if dpkg --compare-versions "$2" lt-nl "2.4.23-3~" ; then
		list_fixup_conffiles | replace_broken_conffiles
	fi

    ;;

    abort-upgrade)
		list_fixup_conffiles | revert_broken_conffiles
    ;;

    *)
	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