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 }