chroot_live-packages: use dpkg-query to see if a package is installed

Closes: #944983
This commit is contained in:
Raphaël Hertzog 2019-12-19 16:21:58 +01:00
parent 04ea46d07b
commit 0647e985fa
2 changed files with 13 additions and 2 deletions

View File

@ -36,3 +36,14 @@ Chroot ()
return "${?}" 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
}

View File

@ -53,7 +53,7 @@ case "${LB_INITSYSTEM}" in
systemd) systemd)
_PACKAGES="${_PACKAGES} systemd-sysv" _PACKAGES="${_PACKAGES} systemd-sysv"
if [ -e chroot/var/lib/dpkg/info/sysvinit.list ] if Chroot_has_package sysvinit
then then
Chroot chroot "dpkg --force-remove-essential --purge sysvinit" Chroot chroot "dpkg --force-remove-essential --purge sysvinit"
fi fi
@ -62,7 +62,7 @@ case "${LB_INITSYSTEM}" in
sysvinit) sysvinit)
_PACKAGES="${_PACKAGES} sysvinit" _PACKAGES="${_PACKAGES} sysvinit"
if [ -e chroot/var/lib/dpkg/info/systemd-sysv.list ] if Chroot_has_package systemd-sysv
then then
Chroot chroot "dpkg --force-remove-essential --purge systemd systemd-sysv" Chroot chroot "dpkg --force-remove-essential --purge systemd systemd-sysv"
fi fi