Remove unneeded double quotes

from download-distfiles.sh and mirror.sh
This commit is contained in:
fosslinux 2025-01-30 22:19:16 +11:00
parent 19c83b80da
commit f3f140783d
2 changed files with 50 additions and 50 deletions

View file

@ -7,54 +7,54 @@
# Optional arguments: Mirrors # Optional arguments: Mirrors
download_source() { download_source() {
local distfiles="${1}" local distfiles=${1}
local url="${2}" local url=${2}
shift 2 shift 2
if [[ "${url}" == git://* ]]; then if [[ ${url} == git://* ]]; then
url="${1}" url=${1}
shift shift
fi fi
local checksum="${1}" local checksum=${1}
local fname="${2}" local fname=${2}
# Default to basename of url if not given # Default to basename of url if not given
fname="${fname:-$(basename "${url}")}" fname=${fname:-$(basename "${url}")}
if [ "${fname}" = "_" ]; then if [ "${fname}" = "_" ]; then
echo "ERROR: ${url} must have a filename specified" echo "ERROR: ${url} must have a filename specified"
exit 1 exit 1
fi fi
local dest_path="${distfiles}/${fname}" local dest_path=${distfiles}/${fname}
if ! [ -e "${dest_path}" ]; then if ! [ -e "${dest_path}" ]; then
echo "Downloading ${fname}" echo "Downloading ${fname}"
if [ "${mirrors_len}" -ne 0 ]; then if [ "${mirrors_len}" -ne 0 ]; then
local mirror_ix="$((RANDOM % mirrors_len))" local mirror_ix=$((RANDOM % mirrors_len))
url="${mirrors[${mirror_ix}]}/${fname}" url=${mirrors[${mirror_ix}]}/${fname}
fi fi
curl --fail --location "${url}" --output "${dest_path}" || true curl --fail --location "${url}" --output "${dest_path}" || true
fi fi
} }
check_source() { check_source() {
local distfiles="${1}" local distfiles=${1}
local url="${2}" local url=${2}
shift 2 shift 2
if [[ "${url}" == git://* ]]; then if [[ ${url} == git://* ]]; then
url="${1}" url=${1}
shift shift
fi fi
local checksum="${1}" local checksum=${1}
local fname="${2}" local fname=${2}
# Default to basename of url if not given # Default to basename of url if not given
fname="${fname:-$(basename "${url}")}" fname=${fname:-$(basename "${url}")}
local dest_path="${distfiles}/${fname}" local dest_path=${distfiles}/${fname}
echo "${checksum} ${dest_path}" | sha256sum -c echo "${checksum} ${dest_path}" | sha256sum -c
} }
set -e set -e
mirrors=( "$@" ) mirrors=( "$@" )
mirrors_len="$#" mirrors_len=$#
cd "$(dirname "$(readlink -f "$0")")" cd "$(dirname "$(readlink -f "$0")")"
mkdir -p distfiles mkdir -p distfiles

View file

@ -12,7 +12,7 @@ if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
exit 1 exit 1
fi fi
dest="$1" dest=$1
if [ ! -d "${dest}" ]; then if [ ! -d "${dest}" ]; then
echo "${dest} must be a directory" echo "${dest} must be a directory"
exit 1 exit 1
@ -22,9 +22,9 @@ if [ ! -w "${dest}" ]; then
echo "you must be able to write to ${dest}" echo "you must be able to write to ${dest}"
exit 1 exit 1
fi fi
dest="$(realpath "${dest}")" dest=$(realpath "${dest}")
state="$2" state=$2
if [ "${state}" = "" ]; then if [ "${state}" = "" ]; then
state="${PWD}/mirrorstate" state="${PWD}/mirrorstate"
fi fi
@ -34,8 +34,8 @@ state="$(realpath "${state}")"
# Download a HTTP file # Download a HTTP file
download_file() { download_file() {
url="${1}" url=${1}
out="${2}" out=${2}
# Download the file # Download the file
continue_arg="" continue_arg=""
if [ -e "${out}" ]; then if [ -e "${out}" ]; then
@ -47,8 +47,8 @@ download_file() {
# Check if a git reference exists in a given repository # Check if a git reference exists in a given repository
git_ref_exists() { git_ref_exists() {
repo="${1}" repo=${1}
ref="${2}" ref=${2}
# change this to git show-ref once it is sufficiently not-new # change this to git show-ref once it is sufficiently not-new
( cd "${repo}" || exit && git cat-file -t "${ref}" >/dev/null 2>&1 ) ( cd "${repo}" || exit && git cat-file -t "${ref}" >/dev/null 2>&1 )
return $? return $?
@ -59,21 +59,21 @@ checksum_file() {
} }
do_file() { do_file() {
uri="${1}" uri=${1}
echo "${uri}" echo "${uri}"
if echo "${uri}" | grep -qE "^https?://"; then if echo "${uri}" | grep -qE "^https?://"; then
# HTTP file # HTTP file
checksum="${2}" checksum=${2}
filename="${3}" filename=${3}
if [ "${filename}" = "" ]; then if [ "${filename}" = "" ]; then
filename="$(basename "${uri}")" filename=$(basename "${uri}")
fi fi
# Check if the file is already downloaded & the checksum is the same # Check if the file is already downloaded & the checksum is the same
dest_file="${dest}/${filename}" dest_file=${dest}/${filename}
if [ -e "${dest_file}" ]; then if [ -e "${dest_file}" ]; then
existing_checksum="$(checksum_file "${dest_file}")" existing_checksum=$(checksum_file "${dest_file}")
if [ "${checksum}" = "${existing_checksum}" ]; then if [ "${checksum}" = "${existing_checksum}" ]; then
# There is nothing we need to do here # There is nothing we need to do here
return return
@ -82,10 +82,10 @@ do_file() {
# Attempt up to 2 times # Attempt up to 2 times
retries=2 retries=2
matching="no" matching=no
while [ "${retries}" -gt 0 ]; do while [ "${retries}" -gt 0 ]; do
download_file "${uri}" "${dest}/${filename}" download_file "${uri}" "${dest}/${filename}"
my_checksum="$(checksum_file "${dest_file}")" my_checksum=$(checksum_file "${dest_file}")
if [ "${checksum}" = "${my_checksum}" ]; then if [ "${checksum}" = "${my_checksum}" ]; then
matching="yes" matching="yes"
break break
@ -105,28 +105,28 @@ do_file() {
# Creating a tarball from a git repository # Creating a tarball from a git repository
# Very unfortunately, different sites have different rules. # Very unfortunately, different sites have different rules.
uri_path="${uri#git://}" uri_path=${uri#git://}
# GitHub does not have git:// protocol support # GitHub does not have git:// protocol support
if echo "${uri}" | grep -Eq "^git://github.com"; then if echo "${uri}" | grep -Eq "^git://github.com"; then
uri="https://${uri_path}" uri=https://${uri_path}
fi fi
repo="${uri%~*}" repo=${uri%~*}
outdir="${state}/git/${repo#*://}" outdir=${state}/git/${repo#*://}
reference="${uri##*~}" reference=${uri##*~}
http_src="${2}" http_src=${2}
checksum="${3}" checksum=${3}
tarball="${4:-$(basename "${http_src}")}" tarball=${4:-$(basename "${http_src}")}
if [ "${tarball}" = "_" ]; then if [ "${tarball}" = "_" ]; then
echo "${uri}: ERROR! Must have tarball name if no http source." echo "${uri}: ERROR! Must have tarball name if no http source."
exit 1 exit 1
fi fi
tarball="${dest}/${tarball}" tarball=${dest}/${tarball}
# Check if tarball already generated + matches checksum # Check if tarball already generated + matches checksum
checksum="${3}" checksum=${3}
if [ -e "${tarball}" ]; then if [ -e "${tarball}" ]; then
existing_checksum="$(checksum_file "${tarball}")" existing_checksum=$(checksum_file "${tarball}")
if [ "${existing_checksum}" = "${checksum}" ]; then if [ "${existing_checksum}" = "${checksum}" ]; then
return return
fi fi
@ -151,13 +151,13 @@ do_file() {
fi fi
# Generate the prefix for the tarball # Generate the prefix for the tarball
prefix_ref="${reference}" prefix_ref=${reference}
# All git repositories we already use remove "v"s from the beginning # All git repositories we already use remove "v"s from the beginning
# of branch/tag names in the tarball prefix # of branch/tag names in the tarball prefix
if echo "${reference}" | grep -Eq "^v[0-9]"; then if echo "${reference}" | grep -Eq "^v[0-9]"; then
prefix_ref="$(echo "${reference}" | sed "s/^v//")" prefix_ref=$(echo "${reference}" | sed "s/^v//")
fi fi
prefix="$(basename "${repo}" | sed "s/.git$//")-${prefix_ref}" prefix=$(basename "${repo}" | sed "s/.git$//")-${prefix_ref}
( (
cd "${outdir}" || exit cd "${outdir}" || exit
@ -168,7 +168,7 @@ do_file() {
git archive "${reference}" -o "${tarball}" --prefix "${prefix}/" git archive "${reference}" -o "${tarball}" --prefix "${prefix}/"
) )
my_checksum="$(sha256sum "${tarball}" | cut -d' ' -f1)" my_checksum=$(sha256sum "${tarball}" | cut -d' ' -f1)
if [ "${my_checksum}" != "${checksum}" ]; then if [ "${my_checksum}" != "${checksum}" ]; then
echo "${uri}: generated tarball does not match checksum" echo "${uri}: generated tarball does not match checksum"
exit 1 exit 1
@ -180,6 +180,6 @@ for src in steps/*/sources; do
while read -r line; do while read -r line; do
# shellcheck disable=SC2086 # shellcheck disable=SC2086
do_file ${line} do_file ${line}
uri="$(echo "${line}" | cut -d' ' -f1)" uri=$(echo "${line}" | cut -d' ' -f1)
done < "${src}" done < "${src}"
done done