diff --git a/api b/api index 2ff485f6436..45afb7c48ac 100755 --- a/api +++ b/api @@ -246,29 +246,21 @@ anything_installed_from_uri_suite_component() { #Given an apt repository uri, su local repofile for repofile in $repofiles ;do #search the repo-file for installed packages + + local packages_in_repo="$(grep '^Package' "$repofile" | awk '{print $2}' | sort)" + local installed_packages="$(apt list --installed 2>/dev/null | tail -n +2 | awk -F/ '{print $1}')" + local apt_cache_policy_output="$(echo "$packages_in_repo" | list_intersect "$installed_packages" | tr '\n' ' ' | xargs -r apt-cache policy)" - grep '^Package' "$repofile" | awk '{print $2}' | while read -r package ;do - if package_installed "$package" ;then - #this package is installed; check if the version available on this repo is the current version (prevents false positives package being installed from another uri/suite/component) - #component is an optional specification - if [ -z "$3" ]; then - if apt-cache policy "$package" | grep -B1 "$(echo "$1" | sed 's+.*://++g' | sed "s,/$,,") $2" | head -n1 | awk '{print $1}' | grep -Fq '***' ;then - echo "Package installed: $package" - exit 1 - fi - else - if apt-cache policy "$package" | grep -B1 "$(echo "$1" | sed 's+.*://++g' | sed "s,/$,,") $2/$3" | head -n1 | awk '{print $1}' | grep -Fq '***' ;then - echo "Package installed: $package" - exit 1 - fi - fi + if [ -z "$3" ]; then + if echo "$apt_cache_policy_output" | grep -B1 "$(echo "$1" | sed 's+.*://++g' | sed "s,/$,,") $2" | awk '{print $1}' | grep -Fq '***' ;then + found=1 + break + fi + else + if echo "$apt_cache_policy_output" | grep -B1 "$(echo "$1" | sed 's+.*://++g' | sed "s,/$,,") $2/$3" | awk '{print $1}' | grep -Fq '***' ;then + found=1 + break fi - done #if exit code is 1, search was successful. If exit code is 0, no packages from the repo were installed. - - found=$? - - if [ $found == 1 ];then - break fi done