Skip to content

Commit

Permalink
api: update package_available to only return true if the package is…
Browse files Browse the repository at this point in the history
… available for the default dpkg architecture
  • Loading branch information
theofficialgman committed Dec 4, 2023
1 parent ec09393 commit 7ffb491
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 7ffb491

Please sign in to comment.