#!/usr/bin/env bash # SPDX-FileCopyrightText: 2022 fosslinux # # SPDX-License-Identifier: GPL-3.0-or-later check_source() { local distfiles="${1}" local url="${2}" local checksum="${3}" local fname="${4}" # Default to basename of url if not given fname="${fname:-$(basename "${url}")}" local dest_path="${distfiles}/${fname}" echo "${checksum} ${dest_path}" | sha256sum -c } set -e cd "$(dirname "$(readlink -f "$0")")" mkdir -p distfiles options=$(mktemp) # shellcheck disable=SC2064 trap "rm -f $options" EXIT # shellcheck disable=SC2028 { echo fail echo location echo parallel echo silent echo write-out = '"%{http_code} %{url} %{errormsg}\n"' echo } > "$options" # First, try to download anything missing - ignore failing mirrors for entry in steps/*; do [ -e "${entry}/sources" ] || continue # shellcheck disable=SC2162 while read -a array; do { echo url = "${array[0]}" echo output = "distfiles/${array[2]:-$(basename "${array[0]}")}" echo } >> "$options" done < "${entry}/sources" done curl -K "$options" # Then, check if everything has been obtained at least once for entry in steps/*; do [ -e "${entry}/sources" ] || continue # shellcheck disable=SC2162 while read line; do # This is intentional - we want to split out ${line} into separate arguments. # shellcheck disable=SC2086 check_source distfiles ${line} done < "${entry}/sources" done