From 88ea21dfc94ac6ed63f64dccf403e94d1d901665 Mon Sep 17 00:00:00 2001 From: fosslinux Date: Fri, 27 Dec 2024 12:19:55 +1100 Subject: [PATCH] Add mirror support to download-distfiles.sh --- download-distfiles.sh | 9 +++++++++ mirror.sh | 2 -- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/download-distfiles.sh b/download-distfiles.sh index 0287b727..6f58911d 100755 --- a/download-distfiles.sh +++ b/download-distfiles.sh @@ -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 diff --git a/mirror.sh b/mirror.sh index 3e6bac2c..29a4b9f6 100755 --- a/mirror.sh +++ b/mirror.sh @@ -121,8 +121,6 @@ do_file() { echo "${uri}: ERROR! Must have tarball name if no http source." exit 1 fi - # Heuristic: all tarball filenames start with t - suffix="t${tarball#*.t}" tarball="${dest}/${tarball}" # Check if tarball already generated + matches checksum