[neon/neon/livecd-rootfs/Neon/release] live-build/ubuntu-server/hooks: fix: Always use `dpkg-divert` instead of altering files maintained by packages

Philip Roche null at kde.org
Mon Feb 5 10:40:28 GMT 2024


Git commit 8f8415e1dc84eba6009feeb7605af26eddd512de by Philip Roche.
Committed on 22/01/2024 at 13:27.
Pushed by jriddell into branch 'Neon/release'.

fix: Always use `dpkg-divert` instead of altering files maintained by packages

Altering a file maintained by a package can lead to unexpected behaviou expecially in
this case where packages are being removed and added.

Instead use `dpkg-divert` to allow us to mock `lxd` to `true` to allow `unminimize` to work
without error and to avoid installing of the `lxd` snap.

M  +7    -2    live-build/ubuntu-server/hooks/01-unminimize.chroot_early

https://invent.kde.org/neon/neon/livecd-rootfs/-/commit/8f8415e1dc84eba6009feeb7605af26eddd512de

diff --git a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early
index cefc73c7..1265966b 100755
--- a/live-build/ubuntu-server/hooks/01-unminimize.chroot_early
+++ b/live-build/ubuntu-server/hooks/01-unminimize.chroot_early
@@ -15,11 +15,16 @@ esac
 # We can't do that at this stage so just neuter the lxd command (the snap
 # will get properly seeded by generic machinery).
 if [ -f "/usr/sbin/lxd" ]; then
-    rm --verbose --force /usr/sbin/lxd
+    dpkg-divert --add --divert /usr/sbin/lxd.REAL --rename /usr/sbin/lxd
     ln -s /bin/true /usr/sbin/lxd
     yes | /usr/local/sbin/unminimize
     # unminimize also uninstalls lxd-installer package
-    # and also removed `/usr/sbin/lxd` as a result so we don't need to restore
+    # and also removed `/usr/sbin/lxd` as a result, so we don't need to restore, but
+    # we do need to remove the mock we used as part of dpkg-divert
+    # first we need to remove the diversion
+    dpkg-divert --remove --no-rename /usr/sbin/lxd
+    # now remove the renamed file that we originally diverted to
+    rm -v /usr/sbin/lxd.REAL
 else
     # if /usr/sbin/lxd doesn't exist then lxd-installer package isn't installed.
     # Instead, we can mock the command to avoid the unminimize script failing



More information about the Neon-commits mailing list