Skip to content

Commit

Permalink
api: anything_installed_from_uri_suite_component simplify function
Browse files Browse the repository at this point in the history
  • Loading branch information
theofficialgman committed Feb 25, 2024
1 parent e69b7dd commit c893bf0
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ anything_installed_from_uri_suite_component() { #Given an apt repository uri, su
debug "$repofiles"

#for every repo-file, check if any of them have an installed file
local found=0
local IFS=$'\n'
local repofile
for repofile in $repofiles ;do
Expand All @@ -252,24 +251,12 @@ anything_installed_from_uri_suite_component() { #Given an apt repository uri, su
local apt_cache_policy_output="$(echo "$packages_in_repo" | list_intersect "$installed_packages" | tr '\n' ' ' | xargs -r apt-cache policy)"

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
echo "$apt_cache_policy_output" | grep -B1 "$(echo "$1" | sed 's+.*://++g' | sed "s,/$,,") $2" | awk '{print $1}' | grep -Fq '***' && return 0
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
echo "$apt_cache_policy_output" | grep -B1 "$(echo "$1" | sed 's+.*://++g' | sed "s,/$,,") $2/$3" | awk '{print $1}' | grep -Fq '***' && return 0
fi
done

#return an exit code
if [ $found == 1 ];then
return 0
else
return 1
fi
return 1
}

remove_repofile_if_unused() { #Given a sources.list.d file, delete it if nothing from that repository is currently installed. Deletion skipped if $2 is 'test'
Expand Down

0 comments on commit c893bf0

Please sign in to comment.