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