Add mirror support to download-distfiles.sh

This commit is contained in:
fosslinux 2024-12-27 12:19:55 +11:00
parent f772cbe131
commit 88ea21dfc9
2 changed files with 9 additions and 2 deletions

View file

@ -4,6 +4,8 @@
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Optional arguments: Mirrors
download_source() {
local distfiles="${1}"
local url="${2}"
@ -15,6 +17,10 @@ download_source() {
local dest_path="${distfiles}/${fname}"
if ! [ -e "${dest_path}" ]; then
echo "Downloading ${fname}"
if [ "${mirrors_len}" -ne 0 ]; then
local mirror_ix="$((RANDOM % mirrors_len))"
url="${mirrors[${mirror_ix}]}/${fname}"
fi
curl --fail --location "${url}" --output "${dest_path}" || true
fi
}
@ -33,6 +39,9 @@ check_source() {
set -e
mirrors=( "$@" )
mirrors_len="$#"
cd "$(dirname "$(readlink -f "$0")")"
mkdir -p distfiles