Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Jan 31, 2024
1 parent 365a670 commit 7340a27
Showing 1 changed file with 65 additions and 203 deletions.
268 changes: 65 additions & 203 deletions tools/download_blender.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,116 +8,48 @@ SUPPORTED_VERSIONS=(
"2.90" "2.91" "2.92" "2.93"
"3.0" "3.1" "3.2" "3.3" "3.4" "3.5" "3.6"
"4.0"
"all"
)

declare -A BLENDER_DOWNLOAD_URL_MACOSX=(
["v2.78"]="https://download.blender.org/release/Blender2.78/blender-2.78c-OSX_10.6-x86_64.zip"
["v2.79"]="https://download.blender.org/release/Blender2.79/blender-2.79a-macOS-10.6.zip"
["v2.80"]=""
["v2.81"]=""
["v2.82"]=""
["v2.83"]="https://download.blender.org/release/Blender2.83/blender-2.83.9-macOS.dmg"
["v2.90"]=""
["v2.91"]=""
["v2.92"]=""
["v2.93"]=""
["v3.0"]=""
["v3.1"]=""
["v3.2"]=""
["v3.3"]=""
declare -A BLENDER_DOWNLOAD_URL_LINUX_PATTERN=(
["v2.78"]="blender-2\\.78([a-z])-linux.*?\\.tar\\.bz2"
["v2.79"]="blender-2\\.79([a-z])-linux.*?\\.tar\\.bz2"
["v2.80"]="blender-2\\.80-linux.*?\\.tar\\.bz2"
["v2.81"]="blender-2\\.81([a-z])-linux.*?\\.tar\\.bz2"
["v2.82"]="blender-2\\.82([a-z])-linux.*?\\.tar\\.xz"
["v2.83"]="blender-2\\.83\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v2.90"]="blender-2\\.90\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v2.91"]="blender-2\\.91\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v2.92"]="blender-2\\.92\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v2.93"]="blender-2\\.93\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v3.0"]="blender-3\\.0\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v3.1"]="blender-3\\.1\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v3.2"]="blender-3\\.2\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v3.3"]="blender-3\\.3\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v3.4"]="blender-3\\.4\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v3.5"]="blender-3\\.5\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v3.6"]="blender-3\\.6\\.([0-9]+)-linux.*?\\.tar\\.xz"
["v4.0"]="blender-4\\.0\\.([0-9]+)-linux.*?\\.tar\\.xz"
)

declare -A BLENDER_DOWNLOAD_URL_WIN64=(
["v2.78"]="https://download.blender.org/release/Blender2.78/blender-2.78c-windows64.zip"
["v2.79"]="https://download.blender.org/release/Blender2.79/blender-2.79b-windows64.zip"
["v2.80"]="https://download.blender.org/release/Blender2.80/blender-2.80-windows64.zip"
["v2.81"]="https://download.blender.org/release/Blender2.81/blender-2.81a-windows64.zip"
["v2.82"]="https://download.blender.org/release/Blender2.82/blender-2.82a-windows64.zip"
["v2.83"]="https://download.blender.org/release/Blender2.83/blender-2.83.9-windows64.zip"
["v2.90"]="https://download.blender.org/release/Blender2.90/blender-2.90.0-windows64.zip"
["v2.91"]="https://download.blender.org/release/Blender2.91/blender-2.91.0-windows64.zip"
["v2.92"]="https://download.blender.org/release/Blender2.92/blender-2.92.0-windows64.zip"
["v2.93"]="https://download.blender.org/release/Blender2.93/blender-2.93.0-windows64.zip"
["v3.0"]="https://download.blender.org/release/Blender3.0/blender-3.0.0-windows-x64.zip"
["v3.1"]="https://download.blender.org/release/Blender3.1/blender-3.1.0-windows-x64.zip"
["v3.2"]="https://download.blender.org/release/Blender3.2/blender-3.2.0-windows-x64.zip"
["v3.3"]="https://download.blender.org/release/Blender3.3/blender-3.3.0-windows-x64.zip"
["v3.4"]="https://download.blender.org/release/Blender3.4/blender-3.4.0-windows-x64.zip"
["v3.5"]="https://download.blender.org/release/Blender3.5/blender-3.5.0-windows-x64.zip"
["v3.6"]="https://download.blender.org/release/Blender3.6/blender-3.6.0-windows-x64.zip"
["v4.0"]="https://download.blender.org/release/Blender4.0/blender-4.0.0-windows-x64.zip"
)

declare -A BLENDER_DOWNLOAD_URL_LINUX=(
["v2.78"]="https://download.blender.org/release/Blender2.78/blender-2.78c-linux-glibc219-x86_64.tar.bz2"
["v2.79"]="https://download.blender.org/release/Blender2.79/blender-2.79b-linux-glibc219-x86_64.tar.bz2"
["v2.80"]="https://download.blender.org/release/Blender2.80/blender-2.80-linux-glibc217-x86_64.tar.bz2"
["v2.81"]="https://download.blender.org/release/Blender2.81/blender-2.81a-linux-glibc217-x86_64.tar.bz2"
["v2.82"]="https://download.blender.org/release/Blender2.82/blender-2.82a-linux64.tar.xz"
["v2.83"]="https://download.blender.org/release/Blender2.83/blender-2.83.9-linux64.tar.xz"
["v2.90"]="https://download.blender.org/release/Blender2.90/blender-2.90.0-linux64.tar.xz"
["v2.91"]="https://download.blender.org/release/Blender2.91/blender-2.91.0-linux64.tar.xz"
["v2.92"]="https://download.blender.org/release/Blender2.92/blender-2.92.0-linux64.tar.xz"
["v2.93"]="https://download.blender.org/release/Blender2.93/blender-2.93.1-linux-x64.tar.xz"
["v3.0"]="https://download.blender.org/release/Blender3.0/blender-3.0.0-linux-x64.tar.xz"
["v3.1"]="https://download.blender.org/release/Blender3.1/blender-3.1.0-linux-x64.tar.xz"
["v3.2"]="https://download.blender.org/release/Blender3.2/blender-3.2.0-linux-x64.tar.xz"
["v3.3"]="https://download.blender.org/release/Blender3.3/blender-3.3.0-linux-x64.tar.xz"
["v3.4"]="https://download.blender.org/release/Blender3.4/blender-3.4.0-linux-x64.tar.xz"
["v3.5"]="https://download.blender.org/release/Blender3.5/blender-3.5.0-linux-x64.tar.xz"
["v3.6"]="https://download.blender.org/release/Blender3.6/blender-3.6.0-linux-x64.tar.xz"
["v4.0"]="https://download.blender.org/release/Blender4.0/blender-4.0.0-linux-x64.tar.xz"
)

declare -A NEED_MOVE_MACOSX=(
["v2.78"]="blender-2.78c-OSX_10.6-x86_64"
["v2.79"]="blender-2.79b-macOS-10.6"
)

declare -A NEED_MOVE_WIN64=(
)

declare -A NEED_MOVE_LINUX=(
["v2.78"]="blender-2.78c-linux-glibc219-x86_64"
["v2.79"]="blender-2.79b-linux-glibc219-x86_64"
["v2.80"]="blender-2.80-linux-glibc217-x86_64"
["v2.81"]="blender-2.81a-linux-glibc217-x86_64"
["v2.82"]="blender-2.82a-linux64"
["v2.83"]="blender-2.83.9-linux64"
["v2.90"]="blender-2.90.0-linux64"
["v2.91"]="blender-2.91.0-linux64"
["v2.92"]="blender-2.92.0-linux64"
["v2.93"]="blender-2.93.1-linux-x64"
["v3.0"]="blender-3.0.0-linux-x64"
["v3.1"]="blender-3.1.0-linux-x64"
["v3.2"]="blender-3.2.0-linux-x64"
["v3.3"]="blender-3.3.0-linux-x64"
["v3.4"]="blender-3.4.0-linux-x64"
["v3.5"]="blender-3.5.0-linux-x64"
["v3.6"]="blender-3.6.0-linux-x64"
["v4.0"]="blender-4.0.0-linux-x64"
)

declare -A BLENDER_CHECKSUM_URL=(
["v2.78"]="https://download.blender.org/release/Blender2.78/release278c.md5"
["v2.79"]="https://download.blender.org/release/Blender2.79/release279b.md5"
["v2.80"]="https://download.blender.org/release/Blender2.80/release280.md5"
["v2.81"]="https://download.blender.org/release/Blender2.81/release281a.md5"
["v2.82"]="https://download.blender.org/release/Blender2.82/release282a.md5"
["v2.83"]="https://download.blender.org/release/Blender2.83/blender-2.83.9.md5"
["v2.90"]="https://download.blender.org/release/Blender2.90/blender-2.90.0.md5"
["v2.91"]="https://download.blender.org/release/Blender2.91/blender-2.91.0.md5"
["v2.92"]="https://download.blender.org/release/Blender2.92/blender-2.92.0.md5"
["v2.93"]="https://download.blender.org/release/Blender2.93/blender-2.93.1.md5"
["v3.0"]="https://download.blender.org/release/Blender3.0/blender-3.0.0.md5"
["v3.1"]="https://download.blender.org/release/Blender3.1/blender-3.1.0.md5"
["v3.2"]="https://download.blender.org/release/Blender3.2/blender-3.2.0.md5"
["v3.3"]="https://download.blender.org/release/Blender3.3/blender-3.3.0.md5"
["v3.4"]="https://download.blender.org/release/Blender3.4/blender-3.4.0.md5"
["v3.5"]="https://download.blender.org/release/Blender3.5/blender-3.5.0.md5"
["v3.6"]="https://download.blender.org/release/Blender3.6/blender-3.6.0.md5"
["v4.0"]="https://download.blender.org/release/Blender4.0/blender-4.0.0.md5"
declare -A BLENDER_CHECKSUM_URL_PATTERN=(
["v2.78"]="release278([a-z])\\.md5"
["v2.79"]="blender279([a-z])\\.md5"
["v2.80"]="blender280\\.md5"
["v2.81"]="blender281([a-z])\\.md5"
["v2.82"]="blender282([a-z])\\.md5"
["v2.83"]="blender-2\\.83\\.([0-9]+)\\.md5"
["v2.90"]="blender-2\\.90\\.([0-9]+)\\.md5"
["v2.91"]="blender-2\\.91\\.([0-9]+)\\.md5"
["v2.92"]="blender-2\\.92\\.([0-9]+)\\.md5"
["v2.93"]="blender-2\\.93\\.([0-9]+)\\.md5"
["v3.0"]="blender-3\\.0\\.([0-9]+)\\.md5"
["v3.1"]="blender-3\\.1\\.([0-9]+)\\.md5"
["v3.2"]="blender-3\\.2\\.([0-9]+)\\.md5"
["v3.3"]="blender-3\\.3\\.([0-9]+)\\.md5"
["v3.4"]="blender-3\\.4\\.([0-9]+)\\.md5"
["v3.5"]="blender-3\\.5\\.([0-9]+)\\.md5"
["v3.6"]="blender-3\\.6\\.([0-9]+)\\.md5"
["v4.0"]="blender-4\\.0\\.([0-9]+)\\.md5"
)

function get_extractor() {
Expand All @@ -135,6 +67,7 @@ function get_extractor() {
function verify_download_integrity() {
local version=${1}
local target_filepath=${2}
local checksum_download_url=${3}

if [ ! -f "${target_filepath}" ]; then
return 1
Expand All @@ -145,7 +78,7 @@ function verify_download_integrity() {
local target_filename download_dir checksum_url checksum_filename
target_filename="$(basename "${target_filepath}")"
download_dir="$(dirname "${target_filepath}")"
checksum_url="${BLENDER_CHECKSUM_URL[${version}]}"
checksum_url="${checksum_download_url}"
checksum_filename="$(basename "${checksum_url}")"

pushd "${download_dir}" 1> /dev/null
Expand Down Expand Up @@ -183,7 +116,8 @@ function verify_download_integrity() {
function download_blender() {
ver=${1}
blender_download_url=${2}
move_from=${3}
checksum_download_url=${3}
move_from=${4}

local download_dir target
download_dir="$(pwd)/downloads"
Expand All @@ -203,7 +137,7 @@ function download_blender() {
fi

# check if file already has been download and verify its signature
if ! verify_download_integrity "${ver}" "${filepath}"; then
if ! verify_download_integrity "${ver}" "${filepath}" "${checksum_download_url}"; then
# create download folder
mkdir -p "${download_dir}"

Expand All @@ -212,7 +146,7 @@ function download_blender() {
curl --location --fail -s "${url}" -o "${filepath}"

# verify integrity of the download
if ! verify_download_integrity "${ver}" "${filepath}"; then
if ! verify_download_integrity "${ver}" "${filepath}" "${checksum_download_url}"; then
echo "Error: Blender ${ver} download failed, please retry. If this happens again, please open a bug report."
echo " URL: ${url}"
exit 1
Expand Down Expand Up @@ -246,30 +180,6 @@ function download_blender() {
popd 1> /dev/null
}

function wait_for_all() {
local status=0
for pid in "$@"; do
wait "${pid}" &&:
(exit $?) && (exit ${status}) &&:; status=$?
done
if [ ${status} -ne 0 ]; then
exit ${status}
fi
}

function check_os() {
# shellcheck disable=SC2003,SC2308,SC2046
if [ "$(uname)" == "Darwin" ]; then
echo "Mac"
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
echo "Linux"
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
echo "Cygwin64"
else
echo "Unknown"
fi
}

# check arguments
if [ $# -ne 2 ]; then
echo "Usage: sh download_blender.sh <version> <output-dir>"
Expand All @@ -284,10 +194,6 @@ if [ -z "${output_dir}" ]; then
exit 1
fi

# check operating system
os=$(check_os)
echo "Operating System is ${os}"

# check if the specified version is supported
supported=0
for v in "${SUPPORTED_VERSIONS[@]}"; do
Expand All @@ -301,70 +207,26 @@ if [ ${supported} -eq 0 ]; then
exit 1
fi

if [ "${version}" = "all" ]; then
pids=()
if [ "${os}" == "Mac" ]; then
for KEY in "${!BLENDER_DOWNLOAD_URL_MACOSX[@]}"; do
url=${BLENDER_DOWNLOAD_URL_MACOSX[${KEY}]}
move_from=""
if [[ "${NEED_MOVE_MACOSX[${KEY}]+_}" == "_" ]]; then
move_from=${NEED_MOVE_MACOSX[${KEY}]}
fi
download_blender "${KEY}" "${url}" "${move_from}" &
pids+=($!)
done
elif [ "${os}" == "Cygwin64" ]; then
for KEY in "${!BLENDER_DOWNLOAD_URL_WIN64[@]}"; do
url=${BLENDER_DOWNLOAD_URL_WIN64[${KEY}]}
move_from=""
if [[ "${NEED_MOVE_WIN64[${KEY}]+_}" == "_" ]]; then
move_from=${NEED_MOVE_WIN64[${KEY}]}
fi
download_blender "${KEY}" "${url}" "${move_from}" &
pids+=($!)
done
elif [ "${os}" == "Linux" ]; then
for KEY in "${!BLENDER_DOWNLOAD_URL_LINUX[@]}"; do
url=${BLENDER_DOWNLOAD_URL_LINUX[${KEY}]}
move_from=""
if [[ "${NEED_MOVE_LINUX[${KEY}]+_}" == "_" ]]; then
move_from=${NEED_MOVE_LINUX[${KEY}]}
fi
download_blender "${KEY}" "${url}" "${move_from}" &
pids+=($!)
done
else
echo "Not supported operating system (OS=${os})"
exit 1
fi
wait_for_all "${pids[@]}"
ver="v${version}"
url="https://download.blender.org/release/Blender${version}/"

pattern=${BLENDER_DOWNLOAD_URL_LINUX_PATTERN["${ver}"]}
url_regex="s/<a href=\"(${pattern})\">.+?<\\/a>.*/\\1/"
if [[ "${version}" =~ ^2.7[89]$ || "${version}" =~ ^2.8[0-2]$ ]]; then
target_blender_file=$(curl -s "${url}" | grep -E "${pattern}" | sed -r "${url_regex}" | sort -r | tail -n 1)
else
if [ "${os}" == "Mac" ]; then
ver=v${version}
url=${BLENDER_DOWNLOAD_URL_MACOSX[${ver}]}
move_from=""
if [[ "${NEED_MOVE_MACOSX[${ver}]+_}" == "_" ]]; then
move_from=${NEED_MOVE_MACOSX[${ver}]}
fi
download_blender "${ver}" "${url}" "${move_from}"
elif [ "${os}" == "Cygwin64" ]; then
ver=v${version}
url=${BLENDER_DOWNLOAD_URL_WIN64[${ver}]}
move_from=""
if [[ "${NEED_MOVE_WIN64[${ver}]+_}" == "_" ]]; then
move_from=${NEED_MOVE_WIN64[${ver}]}
fi
download_blender "${ver}" "${url}" "${move_from}"
elif [ "${os}" == "Linux" ]; then
ver=v${version}
url=${BLENDER_DOWNLOAD_URL_LINUX[${ver}]}
move_from=""
if [[ "${NEED_MOVE_LINUX[${ver}]+_}" == "_" ]]; then
move_from=${NEED_MOVE_LINUX[${ver}]}
fi
download_blender "${ver}" "${url}" "${move_from}"
else
echo "Not supported operating system (OS=${os})"
exit 1
fi
target_blender_file=$(curl -s "${url}" | grep -E "${pattern}" | sed -r "${url_regex}" | sort -n -t . -k 3 | tail -n 1)
fi
download_url="${url}${target_blender_file}"

pattern=${BLENDER_CHECKSUM_URL_PATTERN["${ver}"]}
url_regex="s/<a href=\"(${pattern})\">.+?<\\/a>.*/\\1/"
if [[ "${version}" =~ ^2.7[89]$ || "${version}" =~ ^2.8[0-2]$ ]]; then
target_checksum_file=$(curl -s "${url}" | grep -E "${pattern}" | sed -r "${url_regex}" | sort -r | tail -n 1)
else
target_checksum_file=$(curl -s "${url}" | grep -E "${pattern}" | sed -r "${url_regex}" | sort -n -t . -k 3 | tail -n 1)
fi
checksum_url="${url}${target_checksum_file}"

move_from=$(basename "${target_blender_file}")
download_blender "${ver}" "${download_url}" "${checksum_url}" "${move_from}"

0 comments on commit 7340a27

Please sign in to comment.