summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2016-12-08 03:29:58 +0000
committerBen Hutchings <ben@decadent.org.uk>2016-12-08 03:41:03 +0000
commit82f4bcf00b11e62738692ed24c915654e93e050a (patch)
tree872b7913ee0deda3c9a920fba7c14f01e9fb3049
parent385e3fce65f6cde81afa4034e7278fe767a34f1a (diff)
Fix initramfs.conf move to ensure default values are upgraded
When we upgrade from a version earlier than 0.123, initramfs.conf is transfered from initramfs-tools to initramfs-tools-core and is not modified. But if it has not been changed from the default shipped in the old version, it should be upgraded to the new default. An upgrade directly from Debian stable (0.120+deb8u2) to testing (0.125) should change BUSYBOX=yes to BUSYBOX=auto but does not. Andreas Beckmann extracted and adapted the code from dpkg-maintscript-helper for conffile removal and renaming, that has the necessary checks. I've simplified that a little bit to reduce code churn. Thanks: Andreas Beckmann <anbe@debian.org> Signed-off-by: Ben Hutchings <ben@decadent.org.uk> Closes: #822671, #825929
-rw-r--r--debian/initramfs-tools-core.postinst36
-rw-r--r--debian/initramfs-tools.postinst33
-rwxr-xr-xdebian/initramfs-tools.postrm33
-rwxr-xr-xdebian/initramfs-tools.preinst34
4 files changed, 117 insertions, 19 deletions
diff --git a/debian/initramfs-tools-core.postinst b/debian/initramfs-tools-core.postinst
index cd69e02..395e997 100644
--- a/debian/initramfs-tools-core.postinst
+++ b/debian/initramfs-tools-core.postinst
@@ -7,15 +7,37 @@ if [ ! -e /etc/initramfs-tools/modules ]; then
> /etc/initramfs-tools/modules
fi
+mvverbose=-v
+
+# from dpkg-maintscript-helper, modified
+ensure_package_owns_file() {
+ local PACKAGE="$1"
+ local FILE="$2"
+
+ dpkg-query -L "$PACKAGE" | grep -F -q -x "$FILE"
+}
+
+# from dpkg-maintscript-helper, modified
+finish_mv_conffile() {
+ local CONFFILE="$1"
+ local PACKAGE="$2"
+
+ rm $mvverbose -f "$CONFFILE.dpkg-remove"
+
+ [ -e "$CONFFILE.dpkg-backup" ] || return 0
+ ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
+
+ echo "Preserving user changes to $CONFFILE (now owned by $PACKAGE)..."
+ if [ -e "$CONFFILE" ]; then
+ mv $mvverbose -f "$CONFFILE" "$CONFFILE.dpkg-new"
+ fi
+ mv $mvverbose -f "$CONFFILE.dpkg-backup" "$CONFFILE"
+}
+
# When installing as a new dependency of initramfs-tools, or upgrading
# from <0.123, we need to move initramfs.conf back into place.
-if [ "$1" = configure ] && dpkg --compare-versions "$2" lt 0.123~ && \
- [ -f /etc/initramfs-tools/initramfs.conf.dpkg-backup ]; then
- # On fresh installation ($2 is empty), overwrite the shipped
- # initramfs.conf. Otherwise use -n to avoid overwriting user
- # configuration if somehow both files exist.
- mv ${2:+-n} /etc/initramfs-tools/initramfs.conf.dpkg-backup \
- /etc/initramfs-tools/initramfs.conf
+if [ "$1" = configure ] && dpkg --compare-versions "$2" lt 0.123~; then
+ finish_mv_conffile /etc/initramfs-tools/initramfs.conf initramfs-tools-core
fi
#DEBHELPER#
diff --git a/debian/initramfs-tools.postinst b/debian/initramfs-tools.postinst
index 72e8b97..4e35c79 100644
--- a/debian/initramfs-tools.postinst
+++ b/debian/initramfs-tools.postinst
@@ -2,12 +2,37 @@
set -e
+mvverbose=-v
+
+# from dpkg-maintscript-helper, modified
+ensure_package_owns_file() {
+ local PACKAGE="$1"
+ local FILE="$2"
+
+ dpkg-query -L "$PACKAGE" | grep -F -q -x "$FILE"
+}
+
+# from dpkg-maintscript-helper, modified
+finish_mv_conffile() {
+ local CONFFILE="$1"
+ local PACKAGE="$2"
+
+ rm $mvverbose -f "$CONFFILE.dpkg-remove"
+
+ [ -e "$CONFFILE.dpkg-backup" ] || return 0
+ ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
+
+ echo "Preserving user changes to $CONFFILE (now owned by $PACKAGE)..."
+ if [ -e "$CONFFILE" ]; then
+ mv $mvverbose -f "$CONFFILE" "$CONFFILE.dpkg-new"
+ fi
+ mv $mvverbose -f "$CONFFILE.dpkg-backup" "$CONFFILE"
+}
+
# If initramfs-tools-core was fully upgraded to 0.123 before our
# preinst ran, we need to move initramfs.conf back into place.
-if [ "$1" = configure ] && [ -n "$2" ] && dpkg --compare-versions "$2" lt 0.123~ && \
- [ -f /etc/initramfs-tools/initramfs.conf.dpkg-backup ]; then
- mv -n /etc/initramfs-tools/initramfs.conf.dpkg-backup \
- /etc/initramfs-tools/initramfs.conf
+if [ "$1" = configure ] && [ -n "$2" ] && dpkg --compare-versions "$2" lt 0.123~; then
+ finish_mv_conffile /etc/initramfs-tools/initramfs.conf initramfs-tools-core
fi
# Regenerate initramfs whenever we go to dpkg state `installed'
diff --git a/debian/initramfs-tools.postrm b/debian/initramfs-tools.postrm
index 58e36e2..69f1dca 100755
--- a/debian/initramfs-tools.postrm
+++ b/debian/initramfs-tools.postrm
@@ -2,12 +2,37 @@
set -e
+mvverbose=-v
+
+# from dpkg-maintscript-helper, modified
+ensure_package_owns_file() {
+ local PACKAGE="$1"
+ local FILE="$2"
+
+ dpkg-query -L "$PACKAGE" | grep -F -q -x "$FILE"
+}
+
+# from dpkg-maintscript-helper
+abort_rm_conffile() {
+ local CONFFILE="$1"
+ local PACKAGE="$2"
+
+ ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
+
+ if [ -e "$CONFFILE.dpkg-remove" ]; then
+ echo "Reinstalling $CONFFILE that was moved away"
+ mv $mvverbose "$CONFFILE.dpkg-remove" "$CONFFILE"
+ fi
+ if [ -e "$CONFFILE.dpkg-backup" ]; then
+ echo "Reinstalling $CONFFILE that was backupped"
+ mv $mvverbose "$CONFFILE.dpkg-backup" "$CONFFILE"
+ fi
+}
+
# If aborting an upgrade from <0.123, we need to move initramfs.conf back
# into place.
-if [ "$1" = abort-upgrade ] && dpkg --compare-versions "$2" lt 0.123~ && \
- [ -f /etc/initramfs-tools/initramfs.conf.dpkg-backup ]; then
- mv -n /etc/initramfs-tools/initramfs.conf.dpkg-backup \
- /etc/initramfs-tools/initramfs.conf
+if [ "$1" = abort-upgrade ] && dpkg --compare-versions "$2" lt 0.123~; then
+ abort_rm_conffile /etc/initramfs-tools/initramfs.conf initramfs-tools
fi
#DEBHELPER#
diff --git a/debian/initramfs-tools.preinst b/debian/initramfs-tools.preinst
index c9b5168..99144bb 100755
--- a/debian/initramfs-tools.preinst
+++ b/debian/initramfs-tools.preinst
@@ -2,14 +2,40 @@
set -e
+mvverbose=-v
+
+# from dpkg-maintscript-helper, modified
+ensure_package_owns_file() {
+ local PACKAGE="$1"
+ local FILE="$2"
+
+ dpkg-query -L "$PACKAGE" | grep -F -q -x "$FILE"
+}
+
+# from dpkg-maintscript-helper
+prepare_rm_conffile() {
+ local CONFFILE="$1"
+ local PACKAGE="$2"
+
+ [ -e "$CONFFILE" ] || return 0
+ ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
+
+ local md5sum="$(md5sum $CONFFILE | sed -e 's/ .*//')"
+ local old_md5sum="$(dpkg-query -W -f='${Conffiles}' $PACKAGE | \
+ sed -n -e "\' $CONFFILE ' { s/ obsolete$//; s/.* //; p }")"
+ if [ "$md5sum" != "$old_md5sum" ]; then
+ mv $mvverbose -f "$CONFFILE" "$CONFFILE.dpkg-backup"
+ else
+ mv $mvverbose -f "$CONFFILE" "$CONFFILE.dpkg-remove"
+ fi
+}
+
# When upgrading from <0.123, we need to move initramfs.conf away so
# dpkg will stop remembering it as an 'obsolete' conffile for us. The
# postinst of either initramfs-tools or initramfs-tools-core will move
# it back.
-if [ "$1" = upgrade ] && dpkg --compare-versions "$2" lt 0.123~ && \
- [ -f /etc/initramfs-tools/initramfs.conf ]; then
- mv /etc/initramfs-tools/initramfs.conf \
- /etc/initramfs-tools/initramfs.conf.dpkg-backup
+if [ "$1" = upgrade ] && dpkg --compare-versions "$2" lt 0.123~; then
+ prepare_rm_conffile /etc/initramfs-tools/initramfs.conf initramfs-tools
fi
#DEBHELPER#