From 0647e985fa05d09a7fecc801e9e23d6b513b7de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= Date: Thu, 19 Dec 2019 16:21:58 +0100 Subject: [PATCH] chroot_live-packages: use dpkg-query to see if a package is installed Closes: #944983 --- functions/chroot.sh | 11 +++++++++++ scripts/build/chroot_live-packages | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/functions/chroot.sh b/functions/chroot.sh index 88c5466b8..0b54a3925 100755 --- a/functions/chroot.sh +++ b/functions/chroot.sh @@ -36,3 +36,14 @@ Chroot () return "${?}" } + +Chroot_has_package() { + PACKAGE="${1}"; shift + CHROOT="${2:-chroot}"; shift + + if dpkg-query --admindir=${CHROOT}/var/lib/dpkg -s ${PACKAGE} >/dev/null 2>&1 | grep -q "^Status: install" + then + return 0 + fi + return 1 +} diff --git a/scripts/build/chroot_live-packages b/scripts/build/chroot_live-packages index f3e52fc0f..a04e37667 100755 --- a/scripts/build/chroot_live-packages +++ b/scripts/build/chroot_live-packages @@ -53,7 +53,7 @@ case "${LB_INITSYSTEM}" in systemd) _PACKAGES="${_PACKAGES} systemd-sysv" - if [ -e chroot/var/lib/dpkg/info/sysvinit.list ] + if Chroot_has_package sysvinit then Chroot chroot "dpkg --force-remove-essential --purge sysvinit" fi @@ -62,7 +62,7 @@ case "${LB_INITSYSTEM}" in sysvinit) _PACKAGES="${_PACKAGES} sysvinit" - if [ -e chroot/var/lib/dpkg/info/systemd-sysv.list ] + if Chroot_has_package systemd-sysv then Chroot chroot "dpkg --force-remove-essential --purge systemd systemd-sysv" fi