diff --git a/api b/api index 8da07fe3741..d1e34ab8e29 100755 --- a/api +++ b/api @@ -1812,6 +1812,24 @@ refresh_all_pkgapp_status() { #for every package-app, if dpkg thinks it's instal # this variable needs to be global to be accessible from the subshells local apt_cache_output="$(echo "$packages" | xargs -r apt-cache policy)" + #redefine package_available() to use apt_cache_output and avoid running apt-cache multiple times + package_available() { #this will only be used in this function's subprocesses. + echo "$apt_cache_output" | grep -x "${1}:" -A2 | grep -vxF " Candidate: (none)" | grep -q "^ Candidate:" + } + + #redefine package_installed to only read /var/lib/dpkg/status once + local dpkg_status="$(grep -x "Package: \($(echo "$packages" | sed 's/:'"$arch"'//g ; s/ /\\|/g')\)" -A 2 /var/lib/dpkg/status)" + #this one only takes off 0.1s on my pi5, so if it causes issues it could be removed + package_installed() { #exit 0 if $1 package is installed, otherwise exit 1 + local package="$1" + [ -z "$package" ] && error "package_installed(): no package specified!" + #find the package listed in /var/lib/dpkg/status + #package_info "$package" + + #directly search /var/lib/dpkg/status + echo "$dpkg_status" | grep -x "Package: $package" -A 2 -m1 | grep -qxF 'Status: install ok installed' + } + # parse apt_cache_output for each package app # generate list of all packages needed by package apps for app in $(list_apps package) ;do