Try both primary and secondary download links URLs (#600)

This commit is contained in:
Geoff Bourne authored and GitHub committed 2026-02-23 08:03:40 -06:00
1 parent 9c027c8680
commit 51a01060c8
1 file changed
+61 -44
+61 -44
View File
@@ -4,18 +4,29 @@ set -eo pipefail
: "${DOWNLOAD_DIR:=${PWD}/.downloads}" : "${DOWNLOAD_DIR:=${PWD}/.downloads}"
: "${PREVIEW:=false}" : "${PREVIEW:=false}"
# Both net and net-secondary hostnames work : "${DOWNLOAD_LINKS_URL:=https://net.web.minecraft-services.net/api/v1.0/download/links}"
: "${DOWNLOAD_LINKS_URL:=https://net-secondary.web.minecraft-services.net/api/v1.0/download/links}" : "${DOWNLOAD_SECONDARY_LINKS_URL:=https://net-secondary.web.minecraft-services.net/api/v1.0/download/links}"
: "${USE_BOX64:=true}" : "${USE_BOX64:=true}"
: "${DEBUG_CURL:=false}"
function isTrue() { function isTrue() {
[[ "${1,,}" =~ ^(true|on|1)$ ]] && return 0 [[ "${1,,}" =~ ^(true|on|1)$ ]] && return 0
return 1 return 1
} }
function replace_version_in_url() { function logWarn() {
local original_url="$1" msg=${1?}
local new_version="$2" echo "WARN $msg" >&2
}
function logError() {
msg=${1?}
echo "ERROR $msg" >&2
}
function replaceVersionInUrl() {
local original_url="${1?}"
local new_version="${2?}"
# Use sed to replace the version number in the URL # Use sed to replace the version number in the URL
local modified_url local modified_url
@@ -38,12 +49,12 @@ function versionFromExisting() {
fi fi
} }
function lookupVersion() { function lookupDownloadUrl() {
platform=${1:?Missing required platform indicator} platform=${1:?Missing required platform indicator}
customVersion=${2:-}
if ! DOWNLOAD_URL=$( for url in "$DOWNLOAD_LINKS_URL" "$DOWNLOAD_SECONDARY_LINKS_URL"; do
curl -fsSL "${DOWNLOAD_LINKS_URL}" | if downloadUrl=$(
curl "${debugCurlArgs[@]}" -fsSL "${url}" |
jq --arg platform "$platform" -rR ' jq --arg platform "$platform" -rR '
try(fromjson) catch({}) | try(fromjson) catch({}) |
.result.links // halt_error(1) | .result.links // halt_error(1) |
@@ -63,45 +74,36 @@ function lookupVersion() {
end end
' '
); then ); then
case "$platform" in echo "$downloadUrl"
serverBedrockLinux) return 0
type=latest
;;
serverBedrockPreviewLinux)
type=preview
;;
*)
echo "ERROR invalid platform $platform"
exit 2
esac
if ! DOWNLOAD_URL=$(curl -fsSL "https://mc-bds-helper.vercel.app/api/$type"); then
echo "ERROR failed to lookup Bedrock version and download URL"
exit 1
fi
fi fi
done
if [[ -n "${customVersion}" && -n "${DOWNLOAD_URL}" ]]; then return 1
DOWNLOAD_URL=$(replace_version_in_url "${DOWNLOAD_URL}" "${customVersion}") }
return
fi
function extractVersionFromUrl() {
url=${1:?missing url}
# shellcheck disable=SC2012 # shellcheck disable=SC2012
if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then if [[ ${url} =~ http.*/.*-(.*)\.zip ]]; then
VERSION=${BASH_REMATCH[1]} echo ${BASH_REMATCH[1]}
return 0
elif versionFromExisting; then elif versionFromExisting; then
echo "WARN Minecraft download page failed, so using existing download of $VERSION" logWarn "Minecraft download page failed, so using existing download of $VERSION"
echo $VERSION
return 0
else else
echo "Failed to lookup download URL: ${DOWNLOAD_URL}" logError "Failed to derive version from download URL: ${DOWNLOAD_URL}"
exit 2 return 1
fi fi
} }
echo "Image info: $(paste -d, -s /etc/image.properties)" echo "Image info: $(paste -d, -s /etc/image.properties)"
debugCurlArgs=()
if [[ ${DEBUG^^} == TRUE ]]; then if [[ ${DEBUG^^} == TRUE ]]; then
set -x set -x
curlArgs=(-v) debugCurlArgs+=(-v)
echo "DEBUG: running as $(id -a) with $(ls -ld /data)" echo "DEBUG: running as $(id -a) with $(ls -ld /data)"
echo " current directory is $(pwd)" echo " current directory is $(pwd)"
fi fi
@@ -138,28 +140,43 @@ else # Original logic: if DIRECT_DOWNLOAD_URL is NOT set, proceed with lookup
case ${VERSION^^} in case ${VERSION^^} in
PREVIEW) PREVIEW)
echo "Looking up latest preview version..." echo "Looking up latest preview version..."
lookupVersion serverBedrockPreviewLinux if ! DOWNLOAD_URL=$(lookupDownloadUrl serverBedrockPreviewLinux); then
logError " failed to lookup download URL"
exit 1
fi
VERSION=$(extractVersionFromUrl "$DOWNLOAD_URL")
;; ;;
LATEST) LATEST)
echo "Looking up latest version..." echo "Looking up latest version..."
lookupVersion serverBedrockLinux if ! DOWNLOAD_URL=$(lookupDownloadUrl serverBedrockLinux); then
logError "failed to lookup download URL"
exit 1
fi
VERSION=$(extractVersionFromUrl "$DOWNLOAD_URL")
;; ;;
EXISTING) EXISTING)
if versionFromExisting; then if versionFromExisting; then
echo "Using existing bedrock server executable" echo "Using existing bedrock server executable"
else else
echo "ERROR unable to locate existing bedrock server executable" logError " unable to locate existing bedrock server executable"
exit 1 exit 1
fi fi
;; ;;
*) *)
# use the given version exactly
if isTrue "$PREVIEW"; then if isTrue "$PREVIEW"; then
echo "Using given preview version ${VERSION}" echo "Using given preview version ${VERSION}"
lookupVersion serverBedrockPreviewLinux "${VERSION}" if ! DOWNLOAD_URL=$(lookupDownloadUrl serverBedrockPreviewLinux); then
logError " failed to lookup Bedrock version and download URL"
exit 1
fi
DOWNLOAD_URL=$(replaceVersionInUrl "${DOWNLOAD_URL}" "${VERSION}")
else else
echo "Using given version ${VERSION}" echo "Using given version ${VERSION}"
lookupVersion serverBedrockLinux "${VERSION}" if ! DOWNLOAD_URL=$(lookupDownloadUrl serverBedrockLinux); then
logError " failed to lookup Bedrock version and download URL"
exit 1
fi
DOWNLOAD_URL=$(replaceVersionInUrl "${DOWNLOAD_URL}" "${VERSION}")
fi fi
;; ;;
esac esac
@@ -177,9 +194,9 @@ if [[ ! -f "$SERVER" ]]; then
TMP_ZIP="$DOWNLOAD_DIR/$(basename "${DOWNLOAD_URL}")" TMP_ZIP="$DOWNLOAD_DIR/$(basename "${DOWNLOAD_URL}")"
echo "Downloading Bedrock server version ${VERSION} ..." echo "Downloading Bedrock server version ${VERSION} ..."
if ! curl "${curlArgs[@]}" -o "${TMP_ZIP}" -A "itzg/minecraft-bedrock-server" -fsSL "${DOWNLOAD_URL}"; then if ! curl "${debugCurlArgs[@]}" -o "${TMP_ZIP}" -A "itzg/minecraft-bedrock-server" -fsSL "${DOWNLOAD_URL}"; then
echo "ERROR failed to download from ${DOWNLOAD_URL}" logError " failed to download from ${DOWNLOAD_URL}
echo " Double check that the given VERSION is valid" Double check that the given VERSION is valid"
exit 2 exit 2
fi fi