From 55d0448c2b0bef163092e251879047d92a58c91e Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Tue, 15 Apr 2008 18:59:26 +0100 Subject: [PATCH] Use triggers when calling update-initramfs in postinst and postrm One complication with the interaction between live-initramfs and update-initramfs is completeness - in a normal Debian system, we do not mind that not all the initrds are updated, so one would simply call "update-initramfs -u" when upgrading (for example) mdadm. However, live-initramfs needs to update *all* initrds (ie. '-u -k all'), but calling this would not use the trigger functionality as 'update-initramfs' will only accept triggering with a single '-u' argument. This is sensible behaviour, as the trigger callback cannot (and shouldn't) be parameterised. The result is this is that we must detect how many kernel flavours we have and revert to the non-triggered call ('-u -k all') if we have more than one. My tests show that this is behaviour is sound, even in the slightly contrived example of updating live-initramfs whilst installing a second kernel, regardless of the interleaving of the calls to postinst. We additionally attempt the same logic in the postrm so that upgrading live-initramfs (for example, in chroot_local-packages) does not result in two calls expensive calls in update-initramfs. --- debian/postinst | 20 ++++++++++++++++++-- debian/postrm | 20 ++++++++++++++++++-- debian/triggers | 1 + 3 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 debian/triggers diff --git a/debian/postinst b/debian/postinst index 752b161..805eb0a 100644 --- a/debian/postinst +++ b/debian/postinst @@ -1,8 +1,24 @@ #!/bin/sh -if [ -x /usr/sbin/update-initramfs ] +case "$(ls -l /boot/vmlinuz* | wc -l)" in + 1) + # We only have one kernel installed, so we can use "-u" + # which will use dpkg-trigger inside update-initramfs + INITRAMFS_ARGS="-u" + ;; + *) + INITRAMFS_ARGS="-u -k all" + ;; +esac + +if [ -x /usr/sbin/update-initramfs ] && [ "x$1" != "xtriggered" ] && \ + dpkg --compare-versions "$DPKG_RUNNING_VERSION" ge '1.14.18' then - update-initramfs -k all -u + # this activates the trigger, if triggers are working + update-initramfs ${INITRAMFS_ARGS} +else + # force it to actually happen + DPKG_MAINTSCRIPT_PACKAGE='' update-initramfs ${INITRAMFS_ARGS} fi #DEBHELPER# diff --git a/debian/postrm b/debian/postrm index 752b161..805eb0a 100644 --- a/debian/postrm +++ b/debian/postrm @@ -1,8 +1,24 @@ #!/bin/sh -if [ -x /usr/sbin/update-initramfs ] +case "$(ls -l /boot/vmlinuz* | wc -l)" in + 1) + # We only have one kernel installed, so we can use "-u" + # which will use dpkg-trigger inside update-initramfs + INITRAMFS_ARGS="-u" + ;; + *) + INITRAMFS_ARGS="-u -k all" + ;; +esac + +if [ -x /usr/sbin/update-initramfs ] && [ "x$1" != "xtriggered" ] && \ + dpkg --compare-versions "$DPKG_RUNNING_VERSION" ge '1.14.18' then - update-initramfs -k all -u + # this activates the trigger, if triggers are working + update-initramfs ${INITRAMFS_ARGS} +else + # force it to actually happen + DPKG_MAINTSCRIPT_PACKAGE='' update-initramfs ${INITRAMFS_ARGS} fi #DEBHELPER# diff --git a/debian/triggers b/debian/triggers new file mode 100644 index 0000000..6c9f454 --- /dev/null +++ b/debian/triggers @@ -0,0 +1 @@ +activate update-initramfs -- 2.1.4