Skip to content

Commit

Permalink
Merge pull request #216 from boostorg/feature/apt-wrapper-scripts
Browse files Browse the repository at this point in the history
Add apt wrapper scripts
  • Loading branch information
Flamefire committed Feb 21, 2024
2 parents 3f8a9bd + 54d6a3e commit 417a443
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/ci.yml
Expand Up @@ -204,18 +204,12 @@ jobs:
SOURCE_KEYS=(${{join(matrix.source_keys, ' ')}})
SOURCES=(${{join(matrix.sources, ' ')}})
# Add this by default
SOURCE_KEYS+=('http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x1E9377A2BA9EF27F')
SOURCES+=(ppa:ubuntu-toolchain-r/test)
for key in "${SOURCE_KEYS[@]}"; do
for i in {1..$NET_RETRY_COUNT}; do
keyfilename=$(basename -s .key $key)
curl -sSL --retry ${NET_RETRY_COUNT:-5} "$key" | sudo gpg --dearmor > /etc/apt/trusted.gpg.d/${keyfilename} && break || sleep 10
done
done
for source in "${SOURCES[@]}"; do
for i in {1..$NET_RETRY_COUNT}; do
sudo add-apt-repository $source && break || sleep 10
done
done
ci/add-apt-keys.sh "${SOURCE_KEYS[@]}"
ci/add-apt-repositories.sh "${SOURCES[@]}"
sudo apt-get -o Acquire::Retries=$NET_RETRY_COUNT update
if [[ -z "${{matrix.install}}" ]]; then
pkgs="${{matrix.compiler}}"
Expand Down
35 changes: 35 additions & 0 deletions ci/add-apt-keys.sh
@@ -0,0 +1,35 @@
#! /bin/bash
#
# Copyright 2023 Alexander Grund
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Add APT keys
# - Each argument should be a key URL
# - $NET_RETRY_COUNT is the amount of retries attempted

set -eu

function do_add_key
{
key_url=$1
# If a keyserver URL (e.g. http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x1E9377A2BA9EF27F)
# use the hash as the filename,
# else assume the URL contains a filename, e.g. https://apt.llvm.org/llvm-snapshot.gpg.key
if [[ "$key_url" =~ .*keyserver.*search=0x([A-F0-9]+) ]]; then
keyfilename="${BASH_REMATCH[1]}.key"
else
keyfilename=$(basename -s .key "$key_url")
fi
echo -e "\tDownloading APT key from '$key_url' to '$keyfilename'"
for i in {1..${NET_RETRY_COUNT:-3}}; do
curl -sSL --retry ${NET_RETRY_COUNT:-5} "$key_url" | sudo gpg --dearmor -o "/etc/apt/trusted.gpg.d/${keyfilename}" && return 0 || sleep 10
done

return 1 # Failed
}

for key_url in "$@"; do
do_add_key "$key_url"
done
25 changes: 25 additions & 0 deletions ci/add-apt-repositories.sh
@@ -0,0 +1,25 @@
#! /bin/bash
#
# Copyright 2023 Alexander Grund, Sam Darwin
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Add APT keys, i.e. wrapper around add-apt-repository
# - Each argument should be a repository name
# - $NET_RETRY_COUNT is the amount of retries attempted

set -eu

function do_add_repository {
name=$1
echo -e "\tAdding repository $name"
for i in {1..${NET_RETRY_COUNT:-3}}; do
sudo -E apt-add-repository -y "$name" && return 0 || sleep 10;
done
return 1 # Failed
}

for repo_name in "$@"; do
do_add_repository "$repo_name"
done

0 comments on commit 417a443

Please sign in to comment.