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

Bug#550584: Initial triggers patch and tracking of highest kernel



On Wed, Mar 09, 2011, Loïc Minier wrote:
>  I'm attaching a naive implementation which doesn't deal with removals
>  and only keeps track of the latest initrd ABI (not of the kernel one).

 I had forgotten the actual flash-kernel call.  I've also added
 a --supported test at the top in this v2.

-- 
Loïc Minier
diff -Nru flash-kernel-2.39/debian/changelog flash-kernel-2.40/debian/changelog
--- flash-kernel-2.39/debian/changelog	2011-03-02 18:59:05.000000000 +0100
+++ flash-kernel-2.40/debian/changelog	2011-03-09 04:37:13.000000000 +0100
@@ -1,3 +1,16 @@
+flash-kernel (2.40) UNRELEASED; urgency=low
+
+  * Add support for triggers.
+  * Add support for tracking and installing only the highest kernel ABI.
+    - Add /etc/initramfs/post-update.d/flash-kernel: write kernel ABI to
+      /var/lib/flash-kernel/highest-abi only if it's the highest we've seen,
+      and call flash-kernel.
+    - Change flash-kernel to call itself with
+      /var/lib/flash-kernel/highest-abi as the explicit ABI to install if it's
+      present.
+
+ -- Loïc Minier <lool@debian.org>  Wed, 09 Mar 2011 02:14:19 +0100
+
 flash-kernel (2.39) unstable; urgency=low
 
   * Add support for Buffalo Linkstation LiveV3 (LS-CHL).  Closes: #612167
diff -Nru flash-kernel-2.39/debian/dirs flash-kernel-2.40/debian/dirs
--- flash-kernel-2.39/debian/dirs	2011-03-02 18:59:05.000000000 +0100
+++ flash-kernel-2.40/debian/dirs	2011-03-09 04:04:15.000000000 +0100
@@ -1 +1,2 @@
 usr/sbin
+var/lib/flash-kernel
diff -Nru flash-kernel-2.39/debian/flash-kernel.postinst flash-kernel-2.40/debian/flash-kernel.postinst
--- flash-kernel-2.39/debian/flash-kernel.postinst	1970-01-01 01:00:00.000000000 +0100
+++ flash-kernel-2.40/debian/flash-kernel.postinst	2011-03-09 02:19:34.000000000 +0100
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+set -e
+
+if [ "$1" = "triggered" ]; then
+    FLASH_KERNEL_NOTRIGGER=y flash-kernel
+fi
+
+#DEBHELPER#
diff -Nru flash-kernel-2.39/debian/initramfs/post-update.d/flash-kernel flash-kernel-2.40/debian/initramfs/post-update.d/flash-kernel
--- flash-kernel-2.39/debian/initramfs/post-update.d/flash-kernel	1970-01-01 01:00:00.000000000 +0100
+++ flash-kernel-2.40/debian/initramfs/post-update.d/flash-kernel	2011-03-09 04:36:44.000000000 +0100
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+set -e
+
+if [ $# != 2 ]; then
+    echo "$0 called without expected arguments (ABI and initrd)" >&2
+    exit 1
+fi
+
+abi="$1"
+# ignored for now
+_initrd="$2"
+
+if ! flash-kernel --supported; then
+    exit 0
+fi
+
+ABI_FILE="/var/lib/flash-kernel/highest-abi"
+
+current=""
+if [ -r "$ABI_FILE" ]; then
+    current="$(cat "$ABI_FILE")"
+fi
+
+if dpkg --compare-version "$current" ge "$abi"; then
+    echo "$1: Current ABI $current is already as high or higher" >&2
+    exit 0
+fi
+
+echo "$1: Updating to new ABI $abi" >&2
+echo "$abi" >"$ABI_FILE.tmp"
+mv -f "$ABI_FILE.tmp" "$ABI_FILE"
+
+flash-kernel
+
diff -Nru flash-kernel-2.39/debian/install flash-kernel-2.40/debian/install
--- flash-kernel-2.39/debian/install	1970-01-01 01:00:00.000000000 +0100
+++ flash-kernel-2.40/debian/install	2011-03-09 04:04:33.000000000 +0100
@@ -0,0 +1 @@
+debian/initramfs/post-update.d/flash-kernel etc/initramfs/post-update.d/
diff -Nru flash-kernel-2.39/debian/triggers flash-kernel-2.40/debian/triggers
--- flash-kernel-2.39/debian/triggers	1970-01-01 01:00:00.000000000 +0100
+++ flash-kernel-2.40/debian/triggers	2011-03-09 02:28:23.000000000 +0100
@@ -0,0 +1 @@
+interest flash-kernel
diff -Nru flash-kernel-2.39/flash-kernel flash-kernel-2.40/flash-kernel
--- flash-kernel-2.39/flash-kernel	2011-03-02 18:59:05.000000000 +0100
+++ flash-kernel-2.40/flash-kernel	2011-03-09 04:04:02.000000000 +0100
@@ -111,6 +111,9 @@
 	esac
 fi
 
+# kernel + initrd installation/upgrade mode, with optional version
+
+# if an explicit version was given, just try installing that
 if [ -n "$1" ]; then
 	kvers="$1"
 	kfile="/boot/vmlinuz-$kvers"
@@ -118,6 +121,31 @@
 	desc="Debian kernel $1"
 	idesc="Debian ramdisk $1"
 else
+	# no version was given, just accumulate multiple calls in a trigger to
+	# only run flash-kernel once; the trigger will just call flash-kernel
+	# again with FLASH_KERNEL_NOTRIGGER set to force a real
+	if [ -z "$FLASH_KERNEL_NOTRIGGER" ] && [ -n "$DPKG_MAINTSCRIPT_PACKAGE" ] && dpkg-trigger --check-supported 2>/dev/null; then
+		# flash-kernel trigger isn't disabled, and we're called from
+		# some package maintainer script (e.g. some postinst calls
+		# flash-kernel), and dpkg-trigger is installed and confirms
+		# that the running dpkg support triggers: we can use the
+		# flash-kernel trigger (asynchronously)
+		if dpkg-trigger --no-await flash-kernel; then
+			exit 0
+		fi
+		# dpkg-trigger failed for some reason, proceed to a normal run
+	fi
+
+	# if the highest ABI file information is present, call ourselves again
+	# in "install kernel and initrd for this ABI" mode
+	ABI_FILE="/var/lib/flash-kernel/highest-abi"
+	if [ -r "$ABI_FILE" ]; then
+		abi="$(cat "$ABI_FILE")"
+		if [ -n "$abi" ]; then
+			exec flash-kernel "$abi"
+		fi
+	fi
+
 	if [ -e /vmlinuz ]; then
 		kfile=/vmlinuz
 		ifile=/initrd.img

Reply to: