Skia has proposed merging ~hyask/autopkgtest-cloud:skia/fix_setup_canonical 
into autopkgtest-cloud:master.

Requested reviews:
  Canonical's Ubuntu QA (canonical-ubuntu-qa)

For more details, see:
https://code.launchpad.net/~hyask/autopkgtest-cloud/+git/autopkgtest-cloud/+merge/480521
-- 
Your team Canonical's Ubuntu QA is requested to review the proposed merge of 
~hyask/autopkgtest-cloud:skia/fix_setup_canonical into autopkgtest-cloud:master.
diff --git a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker-config-production/setup-canonical.sh b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker-config-production/setup-canonical.sh
index 262f79e..490b51a 100644
--- a/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker-config-production/setup-canonical.sh
+++ b/charms/focal/autopkgtest-cloud-worker/autopkgtest-cloud/worker-config-production/setup-canonical.sh
@@ -41,11 +41,16 @@ rm /etc/apt/preferences.d/force-downgrade-to-release.pref
 #
 # Note: autoremove/--autoremove always runs on the entire set of installed
 # packages. Together with --autopurge/purge each removal becomes a purge.
-#
-# Removing '?obsolete' packages may remove the running kernel. This is not
-# expected to be an issue.
 if /usr/lib/apt/apt-helper analyze-pattern '?true' >/dev/null 2>&1; then
-    DEBIAN_FRONTEND=noninteractive eatmydata apt-get -y purge --autoremove '?obsolete'
+   # Avoid removing the running kernel
+   running_kernel_pattern="^linux-.*$(uname -r | sed 's/\./\\./g').*"
+   obsolete_pkgs="$(apt list '?obsolete' 2>/dev/null \
+     | tail -n+2 \
+     | cut -d'/' -f1 \
+     | grep -v "${running_kernel_pattern}" || true)"
+   # Teach shellcheck that word-splitting is a feature here
+   # shellcheck disable=SC2086
+   DEBIAN_FRONTEND=noninteractive eatmydata apt-get -y purge --autoremove ${obsolete_pkgs}
 else
     # We're on an older release (analyze-pattern is not available).
     # Still do an autopurge to get rid of packages that got orphaned
-- 
Mailing list: https://launchpad.net/~canonical-ubuntu-qa
Post to     : canonical-ubuntu-qa@lists.launchpad.net
Unsubscribe : https://launchpad.net/~canonical-ubuntu-qa
More help   : https://help.launchpad.net/ListHelp

Reply via email to