[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#735093: flash-kernel: does not correctly handle removal of the highest-versioned installed kernel package



On Sun, 2014-01-12 at 18:39 +0100, Karsten Merker wrote:
> Package: flash-kernel
> Version: 3.11
> Severity: normal
> Tags: patch
> 
> Flash-Kernel 3.11 does not properly handle a removal of the
> highest-versioned kernel package.  The same applies to current
> git as of 2014-01-12 which will probably be released as 3.12.
> 
> When called from the kernel postinst in this case, it just aborts
> instead of flashing the remaining then-highest-versioned kernel,
> which in specific cases could lead to an unbootable system.
> 
> Attached is a patch against current mainline flash-kernel git
> (as of 7f52719ab0a607b89555baffd1cc8c14207c0f8f).

Thanks.

I think for such "internal" uses an environment variable would be more
appropriate than a command line option, so I've reworked as follows, but
not yet tested (hence debugging code still in place too), although the
bulk of the real logic is taken directly from your patch.

Ian.

diff --git a/debian/changelog b/debian/changelog
index 73e95ff..670680e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+flash-kernel (3.14) UNRELEASED; urgency=low
+
+  * Handle removal of highest kernel version (Closes: #735093). Patch from
+    Karsten Merker.
+
+ -- Ian Campbell <ijc@hellion.org.uk>  Sat, 25 Jan 2014 07:40:41 +0000
+
 flash-kernel (3.13) unstable; urgency=low
 
   [ Ian Campbell ]
diff --git a/debian/copyright b/debian/copyright
index 973a8d1..e12541a 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -7,6 +7,7 @@ Copyright (C) 2006  Joey Hess  <joeyh@debian.org>
 Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011  Martin Michlmayr <tbm@cyrius.com>
 Copyright (C) 2011  Loïc Minier <lool@dooz.org>
 Copyright (C) 2012-2014  Ian Campbell <ijc@hellion.org.uk>
+Copyright (C) 2014  Karsten Merker <merker@debian.org>
 
     This program is free software; you can redistribute it and/or
     modify it under the terms of the GNU General Public License
diff --git a/functions b/functions
index 42c28e7..3d271df 100644
--- a/functions
+++ b/functions
@@ -365,14 +365,37 @@ if [ "x$1" = "x--supported" ]; then
 	exit 1
 fi
 
-# kernel + initrd installation/upgrade mode, with optional version
+# $FK_KERNEL_HOOK_SCRIPT is set when main() is called from
+# /etc/kernel/* to be able to differentiate between being called
+# upon kernel installation or kernel removal
 
+# kernel + initrd installation/upgrade mode, with optional version
 kvers="$1"
+echo "CONTEXT $FK_KERNEL_HOOK_SCRIPT VERS $kvers"
 latest_version=$(linux-version list | linux-version sort | tail -1)
-if [ -n "$kvers" ] && [ "$kvers" != "$latest_version" ]; then
+if [ -n "$kvers" ] && [ "$kvers" != "$latest_version" ] && [ "$FK_KERNEL_HOOK_SCRIPT" = "postinst.d" ]; then
 	echo "Ignoring old or unknown version $kvers (latest is $latest_version)" >&2
 	exit 0
 fi
+
+if [ -n "$kvers" ] && [ "$FK_KERNEL_HOOK_SCRIPT" = "postrm.d" ]; then
+	if $(linux-version compare "$kvers" lt "$latest_version"); then
+		echo "flash-kernel: Removal of kernel version ${kvers}." >&2
+		echo "flash-kernel: A higher version (${latest_version}) is still installed, no reflashing required." >&2
+		exit 0
+	else
+		echo "flash-kernel: Kernel ${kvers} has been removed." >&2
+		if [ -n "${latest_version}" ]; then
+			echo "flash-kernel: Flashing the remaining highest-versioned kernel (${latest_version})." >&2
+		else
+			echo "flash-kernel: WARNING: No other kernel packages found!" >&2
+			echo "flash-kernel: The system might be unbootable." >&2
+			echo "flash-kernel: Please install a kernel package before rebooting the system." >&2
+			exit 0
+		fi
+	fi
+fi
+
 kvers="$latest_version"
 
 # accumulate multiple calls in a trigger to only run flash-kernel once; the
diff --git a/kernel-hook/zz-flash-kernel b/kernel-hook/zz-flash-kernel
index 336134a..bcf32c6 100755
--- a/kernel-hook/zz-flash-kernel
+++ b/kernel-hook/zz-flash-kernel
@@ -29,7 +29,8 @@ _version="${version%\'}"
 # only call flash-kernel once on install, upgrade, removal or purge
 # XXX apparently kernel postinst doesn't always pass maintainer scripts
 # arguments
-case "$(basename "$(dirname "$self")")/$action" in
+export FK_KERNEL_HOOK_SCRIPT="$(basename "$(dirname "$self")")"
+case "$FK_KERNEL_HOOK_SCRIPT/$action" in
   postinst.d/configure|postinst.d/|postrm.d/remove|postrm.d/)
     exec flash-kernel "$abi"
   ;;

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: