From 8ed7991db8bad4e957670ffa42994e476d431e71 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sat, 4 Jun 2016 23:37:04 +0100 Subject: [PATCH] linux-image: Make a newly installed kernel the default if the package was previously removed Currently the postinst script distinguishes installation vs upgrade by checking whether its second argument is empty. However, it will only be empty if the package was *never* installed before, or was purged. If the package has been installed, then removed, and is now being installed again, it's seen as an upgrade. Unfortunately dpkg only tells the preinst script whether or not this is an upgrade. So create a flag file there, consume it in postinst and remove it in postrm. --- debian/changelog | 2 ++ debian/templates/image.postinst.in | 3 ++- debian/templates/image.postrm.in | 2 ++ debian/templates/image.preinst.in | 6 ++++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 49966b0f1..61c4aca20 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,8 @@ linux (4.6-1~exp3) UNRELEASED; urgency=medium for minimal_swap, no_symlinks, use_hard_links and *_hook parameters in /etc/kernel-img.conf (Closes: #730073). * linux-image: postrm: Update default symlinks before running hook scripts + * linux-image: Make a newly installed kernel the default if the package + was previously removed -- Ben Hutchings Sat, 04 Jun 2016 18:33:11 +0100 diff --git a/debian/templates/image.postinst.in b/debian/templates/image.postinst.in index 09960b85e..ebd17df89 100755 --- a/debian/templates/image.postinst.in +++ b/debian/templates/image.postinst.in @@ -13,12 +13,13 @@ fi depmod $version -if [ -z "$2" ]; then +if [ -f /lib/modules/$version/.fresh-install ]; then change=install else change=upgrade fi linux-update-symlinks $change $version $image_path +rm -f /lib/modules/$version/.fresh-install if [ -d /etc/kernel/postinst.d ]; then DEB_MAINT_PARAMS="$*" run-parts --report --exit-on-error --arg=$version \ diff --git a/debian/templates/image.postrm.in b/debian/templates/image.postrm.in index 9ba8546bd..29e9c8250 100755 --- a/debian/templates/image.postrm.in +++ b/debian/templates/image.postrm.in @@ -3,6 +3,8 @@ version=@abiname@@localversion@ image_path=/boot/@image-stem@-$version +rm -f /lib/modules/$version/.fresh-install + if [ "$1" != upgrade ] && command -v linux-update-symlinks >/dev/null; then linux-update-symlinks remove $version $image_path fi diff --git a/debian/templates/image.preinst.in b/debian/templates/image.preinst.in index e723bed03..8a5658ecd 100755 --- a/debian/templates/image.preinst.in +++ b/debian/templates/image.preinst.in @@ -7,6 +7,12 @@ if [ "$1" = abort-upgrade ]; then exit 0 fi +if [ "$1" = install ]; then + # Create a flag file for postinst + mkdir -p /lib/modules/$version + touch /lib/modules/$version/.fresh-install +fi + if [ -d /etc/kernel/preinst.d ]; then DEB_MAINT_PARAMS="$*" run-parts --report --exit-on-error --arg=$version \ --arg=$image_path /etc/kernel/preinst.d