Skip to content

Commit

Permalink
Add fallback mirror for php PPA when launchpad is down
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Jun 23, 2024
1 parent 9c28f9b commit e020d65
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/scripts/tools/ppa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ add_key() {
key_source=$4
key_file=$5
key_urls=("$key_source")
if [[ "$key_source" =~ launchpad.net|debian.org|setup-php.com ]]; then
if [[ "$key_source" =~ launchpad.net|debian.org ]]; then
fingerprint="$("${ID}"_fingerprint "$ppa" "$ppa_url" "$package_dist")"
sks_params="op=get&options=mr&exact=on&search=0x$fingerprint"
key_urls=("${sks[@]/%/\/pks\/lookup\?"$sks_params"}")
Expand Down Expand Up @@ -158,13 +158,24 @@ remove_list() {
sudo rm -f "$key_dir"/"${ppa/\//-}"-keyring || true
}

# Function to check if launchpad is up
is_launchpad_up() {
curl -s --head --fail "$lp_ppa/ondrej/php/ubuntu/dists/$VERSION_CODENAME/Release" > /dev/null
}

# Function to add a PPA.
add_ppa() {
set_base_version
ppa=${1:-ondrej/php}
if [[ "$ID" = "ubuntu" || "$ID_LIKE" =~ ubuntu ]] && [[ "$ppa" =~ "ondrej/" ]]; then
[ "${debug:?}" = "debug" ] && add_list "$ppa" "$lp_ppa/$ppa/ubuntu" "$lp_ppa/$ppa/ubuntu" "$VERSION_CODENAME" "main/debug"
add_list "$ppa"
if is_launchpad_up; then
[ "${debug:?}" = "debug" ] && add_list "$ppa" "$lp_ppa/$ppa/ubuntu" "$lp_ppa/$ppa/ubuntu" "$VERSION_CODENAME" "main/debug"
add_list "$ppa"
else
ppa_name="$(basename "$ppa")"
[ "${debug:?}" = "debug" ] && add_list sp/"$ppa_name" "$sp/$ppa/ubuntu" "$sp/$ppa/ubuntu/key.gpg" "$VERSION_CODENAME" "main/debug"
add_list sp/"$ppa_name" "$sp/$ppa/ubuntu" "$sp/$ppa/ubuntu/key.gpg"
fi
elif [[ "$ID" = "debian" || "$ID_LIKE" =~ debian ]] && [[ "$ppa" =~ "ondrej/" ]]; then
[ "${debug:?}" = "debug" ] && add_list "$ppa" "$sury"/"${ppa##*/}"/ "$sury"/"${ppa##*/}"/apt.gpg "$VERSION_CODENAME" "main/debug"
add_list "$ppa" "$sury"/"${ppa##*/}"/ "$sury"/"${ppa##*/}"/apt.gpg
Expand Down Expand Up @@ -198,6 +209,7 @@ lp_ppa='http://ppa.launchpad.net'
key_dir='/usr/share/keyrings'
dist_info_dir='/usr/share/distro-info'
sury='https://packages.sury.org'
sp='https://setup-php.com'
sks=(
'https://keyserver.ubuntu.com'
'https://pgp.mit.edu'
Expand Down

0 comments on commit e020d65

Please sign in to comment.