nerd-fonts/bin/scripts/fetch-archives.sh
Fini Jastrow a1c9300076 fetch-archives: Decouple from patched-fonts dir
[why]
It does not really make sense to couple the names of the download files
to some currently existing directories in the repo. They could be
different, especially if current version and requested version differ.

[how]
Complete rewrite. Fetch the release data from Github and examine the
release database.

Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
2022-12-14 09:45:59 +01:00

72 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Nerd Fonts Version: 2.3.0-RC
# Script Version: 2.0.0
#
# Fetches the current release files.
# It fetches the latest release, not release candidate.
# Or fetches the specified release's files.
#
# The second parameter specifies the beginning of the artifact
# name that shall be fetched. If unspecified all artifacts will
# be fetched.
#
# Example runs
# fetch-archives
# fetch-archives v2.2.2
# fetch-archives v2.2.2 Heavy
# fetch-archives latest HeavyDat
set -e
LINE_PREFIX="# [Nerd Fonts] "
scripts_root_dir="$(cd "$(dirname "$0")" && pwd)"
outputdir=$(realpath "${scripts_root_dir}/../../archives")
if [ $# -ge 1 ]; then
versiontag=$1
else
versiontag="latest"
fi
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")
num=$(jq ".[] | select(.tag_name == \"${versiontag}\") | .assets | length" <<< ${releasedata})
if [ -z "${num}" ]; then
echo "${LINE_PREFIX} Release tag ${versiontag} unknown"
exit 1
fi
files=($(jq -r ".[] | select(.tag_name == \"${versiontag}\") | .assets[].name | @sh" <<< ${releasedata}))
else
echo "${LINE_PREFIX} Fetching latest release archives"
releasedata=$(curl -Lf "https://api.github.com/repos/ryanoasis/nerd-fonts/releases/latest")
versiontag=$(jq -r ".tag_name" <<< ${releasedata})
num=$(jq ".assets | length" <<< ${releasedata})
files=($(jq -r ".assets[].name | @sh" <<< ${releasedata}))
fi
echo "${LINE_PREFIX} Found ${num} artifacts"
if [ $# -ge 2 ]; then
pattern=$2
echo "${LINE_PREFIX} Limiting archive to pattern '${pattern}'"
else
pattern=""
echo "${LINE_PREFIX} No limiting pattern given"
fi
if [ $# -gt 2 ]; then
echo "${LINE_PREFIX} Too many parameters, exiting"
exit 2
fi
for assetname in ${files[@]}; do
assetname=${assetname:1:-1}
if [[ ! "${assetname}" =~ ^"${pattern}" ]]; then
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}" \
|| echo " => error fetching"
done