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

[PATCH 3/4] update-initramfs: Depend on kernel hook scripts rather than $ramdisk invocation



Official Debian and Ubuntu kernel packages will invoke us directly as
part of the $ramdisk handling inherited from kernel-package.  They
will later run our hook script, as will custom packages made with
'make-kpkg' or the upstream 'make deb-pkg'.

Currently, for official packages we perform an update on the first
invocation (possibly deferred using dpkg triggers) and then ignore the
second.  However, the long-term plan is to remove that first
invocation.  Therefore, ignore the first invocation and perform the
update on the second.

Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 kernel/postinst.d/initramfs-tools |   23 ++++++++++-------------
 kernel/postrm.d/initramfs-tools   |   23 ++++++++++-------------
 update-initramfs                  |   29 ++++++++++++++++++++---------
 3 files changed, 40 insertions(+), 35 deletions(-)

diff --git a/kernel/postinst.d/initramfs-tools b/kernel/postinst.d/initramfs-tools
index b36d713..18202e4 100755
--- a/kernel/postinst.d/initramfs-tools
+++ b/kernel/postinst.d/initramfs-tools
@@ -9,19 +9,16 @@ if [ -z "${version}" ]; then
 	exit 2
 fi
 
-# kernel-package passes an extra arg
+# exit if custom kernel does not need an initramfs
+if [ -n "${KERNEL_PACKAGE_VERSION}" -a "$INITRD" = 'No' ]; then
+	exit 0
+fi
+
+# absolute file name of kernel image may be passed as a second argument;
+# create the initrd in the same directory
 if [ -n "$2" ]; then
-	if [ -n "${KERNEL_PACKAGE_VERSION}" ]; then
-		# exit if custom kernel does not need an initramfs
-		if [ "$INITRD" = 'No' ]; then
-			exit 0
-		fi
-		bootdir=$(dirname "$2")
-		bootopt="-b ${bootdir}"
-	else
-		# official Debian linux-images take care themself
-		exit 0
-	fi
+	bootdir=$(dirname "$2")
+	bootopt="-b ${bootdir}"
 fi
 
 # avoid running multiple times
@@ -33,4 +30,4 @@ if [ -n "$DEB_MAINT_PARAMS" ]; then
 fi
 
 # we're good - create initramfs.  update runs do_bootloader
-update-initramfs -c -t -k "${version}" ${bootopt} >&2
+INITRAMFS_TOOLS_KERNEL_HOOK=1 update-initramfs -c -t -k "${version}" ${bootopt} >&2
diff --git a/kernel/postrm.d/initramfs-tools b/kernel/postrm.d/initramfs-tools
index 36fb61f..850dda0 100755
--- a/kernel/postrm.d/initramfs-tools
+++ b/kernel/postrm.d/initramfs-tools
@@ -9,19 +9,16 @@ if [ -z "${version}" ]; then
 	exit 0
 fi
 
-# kernel-package passes an extra arg
+# exit if custom kernel does not need an initramfs
+if [ -n "${KERNEL_PACKAGE_VERSION}" -a "$INITRD" = 'No' ]; then
+	exit 0
+fi
+
+# absolute file name of kernel image may be passed as a second argument;
+# create the initrd in the same directory
 if [ -n "$2" ]; then
-	if [ -n "${KERNEL_PACKAGE_VERSION}" ]; then
-		# exit if custom kernel does not need an initramfs
-		if [ "$INITRD" = 'No' ]; then
-			exit 0
-		fi
-		bootdir=$(dirname "$2")
-		bootopt="-b ${bootdir}"
-	else
-		# official linux-images take care themself
-		exit 0
-	fi
+	bootdir=$(dirname "$2")
+	bootopt="-b ${bootdir}"
 fi
 
 # avoid running multiple times
@@ -33,4 +30,4 @@ if [ -n "$DEB_MAINT_PARAMS" ]; then
 fi
 
 # delete initramfs
-update-initramfs -d -t -k "${version}" ${bootopt} >&2
+INITRAMFS_TOOLS_KERNEL_HOOK=1 update-initramfs -d -t -k "${version}" ${bootopt} >&2
diff --git a/update-initramfs b/update-initramfs
index ba17260..96bcb1f 100755
--- a/update-initramfs
+++ b/update-initramfs
@@ -14,17 +14,28 @@ set -e
 
 [ -r ${CONF} ] && . ${CONF}
 
-if	   $USETRIGGERS						\
-	&& [ x"${DPKG_MAINTSCRIPT_PACKAGE:-}" != x ]		\
-	&& [ $# = 1 ]	 					\
-	&& [ x"$1" = x-u ]					\
-	&& dpkg-trigger --check-supported 2>/dev/null
-then
-	if dpkg-trigger --no-await update-initramfs; then
-		echo "update-initramfs: deferring update (trigger activated)"
+case "$DPKG_MAINTSCRIPT_PACKAGE" in
+linux-image-*)
+	if [ -z "$INITRAMFS_TOOLS_KERNEL_HOOK" ]; then
+		# kernel maintainer script called us directly; ignore
+		# it and let the hook script handle it instead
+		echo "update-initramfs: deferring update (hook will be called later)"
 		exit 0
 	fi
-fi
+	;;
+?*)
+	if	   $USETRIGGERS						\
+		&& [ $# = 1 ]						\
+		&& [ x"$1" = x-u ]					\
+		&& dpkg-trigger --check-supported 2>/dev/null
+	then
+		if dpkg-trigger --no-await update-initramfs; then
+			echo "update-initramfs: deferring update (trigger activated)"
+			exit 0
+		fi
+	fi
+	;;
+esac
 
 usage()
 {
-- 
1.7.4.1



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


Reply to: