Last active
July 31, 2020 19:39
-
-
Save grische/7826531f5bc5da86a0d6129c4836a78b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -u | |
# Release can be for example: "2.90", "Beta", "2.91", "Alpha", ... | |
release=${1:-"Beta"} | |
destination=${2:-.} | |
BUILDER_DOMAIN=${BUILDER_DOMAIN:-"builder.blender.org"} | |
XMLLINT=${XMLLINT:-xmllint} | |
# check if xmllint binary is availble | |
if ! command -v "${XMLLINT}" > /dev/null; then | |
echo "Error: Cannot find ${XMLLINT} binary. Please install the package." | |
exit 1 | |
fi | |
xmllint=$(command -v "${XMLLINT}") | |
# check if curl binary is availble | |
if ! command -v curl > /dev/null; then | |
echo "Error: Cannot find curl binary. Please install the package." | |
exit 1 | |
fi | |
curl=$(command -v curl) | |
echo "Fetching all Blender downloads with version \"${release}\" from \"${BUILDER_DOMAIN}\" to folder \"${destination}\"" | |
# Change into destination directory | |
if ! pushd "${destination}" 1> /dev/null; then | |
echo "Cannot access folder \"${destination}\"" | |
fi | |
# Fetch download links | |
download_hrefs="$(${curl} -s --fail https://${BUILDER_DOMAIN}/download/ | ${xmllint} --html --xpath "//a[contains(.,'${release}')]/@href" - 2> /dev/null)" | |
if [ $? -ne 0 ]; then | |
echo "Unable to find version \"${release}\" on \"${BUILDER_DOMAIN}\"" | |
exit 1 | |
fi | |
# Download the actual packages | |
for href in ${download_hrefs}; | |
do | |
link=${href//href=} | |
link=${link//\"} | |
echo "Downloading $(basename "${link}")" | |
if ! curl -s --fail "https://${BUILDER_DOMAIN}${link}" -O; then | |
echo "ERROR: Unable to download: https://${BUILDER_DOMAIN}${link}" | |
exit 1 | |
fi | |
done | |
echo "Finished downloading files to \"${destination}\"" | |
# Change back into previous folder | |
popd 1> /dev/null || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment