2022-11-28 13:45:26 +02:00
|
|
|
#!/usr/bin/env bash
|
2023-05-13 07:48:24 +02:00
|
|
|
# Nerd Fonts Version: 3.0.1
|
2022-11-29 23:10:19 +02:00
|
|
|
# Script Version: 2.0.0
|
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
|
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")
|
|
|
|
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}))
|
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")
|
|
|
|
versiontag=$(jq -r ".tag_name" <<< ${releasedata})
|
|
|
|
num=$(jq ".assets | length" <<< ${releasedata})
|
|
|
|
files=($(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
|
2022-11-29 17:34:24 +02:00
|
|
|
pattern=$2
|
2022-11-29 23:10:19 +02:00
|
|
|
echo "${LINE_PREFIX} Limiting archive to pattern '${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
|
|
|
|
|
2022-11-29 23:10:19 +02:00
|
|
|
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}" \
|
2022-11-28 13:45:26 +02:00
|
|
|
|| echo " => error fetching"
|
|
|
|
done
|