From 8f8415e1dc84eba6009feeb7605af26eddd512de Mon Sep 17 00:00:00 2001 From: Philip Roche Date: Mon, 22 Jan 2024 12:48:55 +0000 Subject: [PATCH] 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. --- .../ubuntu-server/hooks/01-unminimize.chroot_early | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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