Skip to content

Commit

Permalink
api: remove anything_installed_from_repo function
Browse files Browse the repository at this point in the history
also replace function in brave install script with `anything_installed_from_uri_suite_component`
  • Loading branch information
theofficialgman committed Feb 27, 2024
1 parent c35ead7 commit 7e47d18
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 42 deletions.
41 changes: 0 additions & 41 deletions api
Original file line number Diff line number Diff line change
Expand Up @@ -183,47 +183,6 @@ package_is_new_enough() { #check if the $1 package has an available version grea
fi
}

anything_installed_from_repo() { #Given an apt repository URL, determine if any packages from it are currently installed
[ -z "$1" ] && error "anything_installed_from_repo: A repository URL must be specified."

#user input repo-url. Remove 'https://', and translate '/' to '_' to conform to apt file-naming standard, with trailing _ to ensure full matches
local url="$(echo "$1" | sed 's+.*://++g' | tr '/' '_')_"

#find all package-lists pertaining to the url
local repofiles="$(ls /var/lib/apt/lists/*_Packages | grep -F "$url")"

#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
#search the repo-file for installed packages

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 from backports repos)
if [ "$(sed -n "/^Package: ${package}$/,/Version:/p" "$repofile" | grep '^Version: ' | awk '{print $2}')" == "$(package_installed_version "$package")" ];then
echo "Package installed: $package"
exit 1
fi
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

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

anything_installed_from_uri_suite_component() { #Given an apt repository uri, suite, and component, determine if any packages from it are currently installed
local uri="$1"
local suite="$2"
Expand Down
2 changes: 1 addition & 1 deletion apps/Brave/install-64
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sudo curl -fsSLo /usr/share/keyrings/brave-browser-archive-keyring.gpg https://b

(install_packages brave-browser)
if [ $? != 0 ]; then
if ! anything_installed_from_repo "https://brave-browser-apt-release.s3.brave.com/" ; then
if ! anything_installed_from_uri_suite_component "https://brave-browser-apt-release.s3.brave.com/" stable main ; then
# nothing installed from repo, this check is to prevent removing repos which other pi-apps scripts or the user have used successfully
# safe to remove
sudo rm -f /etc/apt/sources.list.d/brave-browser-release.list /usr/share/keyrings/brave-browser-archive-keyring.gpg
Expand Down

0 comments on commit 7e47d18

Please sign in to comment.