From 7ffb491319887e7bfc4eeba4fe369617997f6722 Mon Sep 17 00:00:00 2001 From: theofficialgman <28281419+theofficialgman@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:48:10 -0500 Subject: [PATCH] api: update `package_available` to only return true if the package is available for the default dpkg architecture --- api | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api b/api index 6211699800..505f47f427 100755 --- a/api +++ b/api @@ -109,13 +109,16 @@ package_installed() { #exit 0 if $1 package is installed, otherwise exit 1 grep "^Package: $package$" /var/lib/dpkg/status -A 1 | tail -n 1 | grep -q 'Status: install ok installed' } -package_available() { #determine if the specified package-name exists in a repository +package_available() { #determine if the specified package-name exists in a local repository for the current dpkg architecture local package="$1" + local arch="$(dpkg --print-architecture)" [ -z "$package" ] && error "package_available(): no package name specified!" #using find and grep to do this is nearly instantaneous, rather than apt-cache which takes several seconds local IFS=$'\n' for file in $(find /var/lib/apt/lists -maxdepth 1 -type f -name "*_Packages") ;do - grep -q "^Package: $package$" "$file" && break + # get all package info up to the end of the stanza (end of stanza indicated by an empty line) + # check if any of the matching package info is for the current dpkg architecture + sed -n '/^Package: '"$package"'$/,/^$/p' "$file" | grep "^Architecture:" | grep -q "$arch\|all" && break done }