Skip to content

Commit

Permalink
Add check for package files when adding PPA
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Sep 14, 2021
1 parent 9adda12 commit c644f65
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/scripts/tools/ppa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ add_key() {
fi
}

# Function to check if a PPA and its lists exist
check_lists() {
ppa=$1
ppa_search=$2
if grep -Eqr "$ppa_search" "$list_dir"; then
list_count="$(find /var/lib/apt/lists -name "*${ppa/\//_}*" | wc -l)"
if [ "$list_count" = "0" ]; then
update_lists "$ppa" "$ppa_search"
fi
return 0;
else
return 1;
fi
}

# Function to add a sources list.
add_list() {
ppa=${1-ondrej/php}
Expand All @@ -104,13 +119,16 @@ add_list() {
package_dist=${4:-"$VERSION_CODENAME"}
branches=${5:-main}
ppa_search="deb .*$ppa_url $package_dist .*$branches"
grep -Eqr "$ppa_search" "$list_dir" && echo "Repository $ppa already exists" && return;
arch=$(dpkg --print-architecture)
[ -e "$key_source" ] && key_file=$key_source || key_file="$key_dir"/"${ppa/\//-}"-keyring.gpg
add_key "$ppa" "$ppa_url" "$package_dist" "$key_source" "$key_file"
echo "deb [arch=$arch signed-by=$key_file] $ppa_url $package_dist $branches" | sudo tee -a "$list_dir"/"${ppa/\//-}".list >/dev/null 2>&1
update_lists "$ppa" "$ppa_search"
. /etc/os-release
if check_lists "$ppa" "$ppa_search"; then
echo "Repository $ppa already exists";
else
arch=$(dpkg --print-architecture)
[ -e "$key_source" ] && key_file=$key_source || key_file="$key_dir"/"${ppa/\//-}"-keyring.gpg
add_key "$ppa" "$ppa_url" "$package_dist" "$key_source" "$key_file"
echo "deb [arch=$arch signed-by=$key_file] $ppa_url $package_dist $branches" | sudo tee -a "$list_dir"/"${ppa/\//-}".list >/dev/null 2>&1
update_lists "$ppa" "$ppa_search"
. /etc/os-release
fi
}

# Function to remove a PPA.
Expand Down

0 comments on commit c644f65

Please sign in to comment.