2022-11-28 13:45:26 +02:00
|
|
|
#!/usr/bin/env bash
|
2024-04-12 16:31:51 +02:00
|
|
|
# Nerd Fonts Version: 3.2.1
|
2023-06-01 10:47:38 +02:00
|
|
|
# Script Version: 2.0.1
|
2022-11-28 13:45:26 +02:00
|
|
|
#
|
2022-11-29 23:10:19 +02:00
|
|
|
# Fetches the current release files.
|
|
|
|
# It fetches the latest release, not release candidate.
|
|
|
|
# Or fetches the specified release's files.
|
2022-11-28 13:45:26 +02:00
|
|
|
#
|
2022-11-29 23:10:19 +02:00
|
|
|
# The second parameter specifies the beginning of the artifact
|
|
|
|
# name that shall be fetched. If unspecified all artifacts will
|
|
|
|
# be fetched.
|
2022-11-28 13:45:26 +02:00
|
|
|
#
|
2022-11-29 17:34:24 +02:00
|
|
|
# Example runs
|
2022-11-29 23:10:19 +02:00
|
|
|
# fetch-archives
|
|
|
|
# fetch-archives v2.2.2
|
|
|
|
# fetch-archives v2.2.2 Heavy
|
|
|
|
# fetch-archives latest HeavyDat
|
2023-06-02 19:28:55 +02:00
|
|
|
# fetch-archives v3.1.0 'Ara.*zip' (just fetch the zip archive)
|
2022-11-28 13:45:26 +02:00
|
|
|
|
2022-11-29 23:10:19 +02:00
|
|
|
set -e
|
2022-11-28 13:45:26 +02:00
|
|
|
|
|
|
|
LINE_PREFIX="# [Nerd Fonts] "
|
2022-11-29 23:10:19 +02:00
|
|
|
scripts_root_dir="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
outputdir=$(realpath "${scripts_root_dir}/../../archives")
|
2022-11-28 13:45:26 +02:00
|
|
|
|
2022-11-29 23:10:19 +02:00
|
|
|
if [ $# -ge 1 ]; then
|
|
|
|
versiontag=$1
|
|
|
|
else
|
|
|
|
versiontag="latest"
|
|
|
|
fi
|
2022-11-28 13:45:26 +02:00
|
|
|
|
2022-11-29 23:10:19 +02:00
|
|
|
if [ "${versiontag}" != "latest" ]; then
|
|
|
|
echo "${LINE_PREFIX} Fetching release archives with version tag '${versiontag}'"
|
|
|
|
releasedata=$(curl -Lf "https://api.github.com/repos/ryanoasis/nerd-fonts/releases")
|
2023-06-01 10:47:38 +02:00
|
|
|
num=$(jq ".[] | select(.tag_name == \"${versiontag}\") | .assets | length" <<< "${releasedata}")
|
2022-11-29 23:10:19 +02:00
|
|
|
if [ -z "${num}" ]; then
|
|
|
|
echo "${LINE_PREFIX} Release tag ${versiontag} unknown"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-06-01 10:47:38 +02:00
|
|
|
files=()
|
|
|
|
while IFS='' read -r file; do
|
|
|
|
files+=("$file")
|
|
|
|
done < <(jq -r ".[] | select(.tag_name == \"${versiontag}\") | .assets[].name | @sh" <<< "${releasedata}")
|
2022-11-29 17:34:24 +02:00
|
|
|
else
|
2022-11-29 23:10:19 +02:00
|
|
|
echo "${LINE_PREFIX} Fetching latest release archives"
|
|
|
|
releasedata=$(curl -Lf "https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest")
|
2023-06-01 10:47:38 +02:00
|
|
|
versiontag=$(jq -r ".tag_name" <<< "${releasedata}")
|
|
|
|
num=$(jq ".assets | length" <<< "${releasedata}")
|
|
|
|
files=()
|
|
|
|
while IFS='' read -r file; do
|
|
|
|
files+=("$file")
|
|
|
|
done < <(jq -r ".assets[].name | @sh" <<< "${releasedata}")
|
2022-11-29 17:34:24 +02:00
|
|
|
fi
|
|
|
|
|
2022-11-29 23:10:19 +02:00
|
|
|
echo "${LINE_PREFIX} Found ${num} artifacts"
|
2022-11-29 17:34:24 +02:00
|
|
|
|
2022-11-29 23:10:19 +02:00
|
|
|
if [ $# -ge 2 ]; then
|
2023-06-02 19:28:55 +02:00
|
|
|
pattern=${2// /\\ }
|
|
|
|
echo "${LINE_PREFIX} Limiting archive to regex '${pattern}'"
|
2022-11-28 13:45:26 +02:00
|
|
|
else
|
2022-11-29 23:10:19 +02:00
|
|
|
pattern=""
|
|
|
|
echo "${LINE_PREFIX} No limiting pattern given"
|
|
|
|
fi
|
|
|
|
if [ $# -gt 2 ]; then
|
|
|
|
echo "${LINE_PREFIX} Too many parameters, exiting"
|
|
|
|
exit 2
|
2022-11-28 13:45:26 +02:00
|
|
|
fi
|
|
|
|
|
2023-06-01 10:47:38 +02:00
|
|
|
for assetname in "${files[@]}"; do
|
2022-11-29 23:10:19 +02:00
|
|
|
assetname=${assetname:1:-1}
|
2023-06-02 19:28:55 +02:00
|
|
|
if [[ ! "${assetname}" =~ ${pattern} ]]; then
|
2022-11-29 23:10:19 +02:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
echo >&2 "${LINE_PREFIX} Fetching ${versiontag}/${assetname}"
|
|
|
|
mkdir -p "${outputdir}"
|
|
|
|
touch "${outputdir}/_Release_${versiontag}"
|
|
|
|
curl --fail -Lo "${outputdir}/${assetname}" "https://github.com/ryanoasis/nerd-fonts/releases/download/${versiontag}/${assetname}" \
|
2022-11-28 13:45:26 +02:00
|
|
|
|| echo " => error fetching"
|
|
|
|
done
|