From 7a27256713417620e7fbbf50d068dfff19aa2d7d Mon Sep 17 00:00:00 2001 From: thedhruvn <11063206+thedhruvn@users.noreply.github.com> Date: Mon, 7 Oct 2024 22:56:14 -0500 Subject: [PATCH 1/2] Fix: eliminated hardcoded URL for custom versions Old behavior: Custom versions used hardcoded download URL. this URL should be dynamically sourced using the lookupVersion command instead. New behavior: lookupVersion takes a second parameter, version, and uses a simple sed replace to insert the version parameter into the download URL dynamically, if it was successfully found. Also, removed old bedrock version shortcuts. This can be restored and modified to use the lookupVersion command to get the right URL if needed. It's unclear whether there's any active servers still running on legacy versions of bedrock (to this author). Resolves #460 --- bedrock-entry.sh | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/bedrock-entry.sh b/bedrock-entry.sh index 5ce9ba6..96377c6 100755 --- a/bedrock-entry.sh +++ b/bedrock-entry.sh @@ -10,8 +10,20 @@ function isTrue() { return 1 } +function replace_version_in_url() { + local original_url="$1" + local new_version="$2" + + # Use sed to replace the version number in the URL + local modified_url + modified_url=$(echo "$original_url" | sed -E "s/(bedrock-server-)[^/]+(\.zip)/\1${new_version}\2/") + + echo "$modified_url" +} + function lookupVersion() { platform=${1:?Missing required platform indicator} + customVersion=${2:-} # shellcheck disable=SC2034 for i in {1..3}; do @@ -23,6 +35,11 @@ function lookupVersion() { DOWNLOAD_URL=$(curl -s https://mc-bds-helper.vercel.app/api/latest) fi + if [[ -n "${customVersion}" && -n "${DOWNLOAD_URL}" ]]; then + DOWNLOAD_URL=$(replace_version_in_url "${DOWNLOAD_URL}" "${customVersion}") + return + fi + # shellcheck disable=SC2012 if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then VERSION=${BASH_REMATCH[1]} @@ -65,27 +82,6 @@ if [[ ${EULA^^} != TRUE ]]; then fi case ${VERSION^^} in - 1.12) - VERSION=1.12.0.28 - ;; - 1.13) - VERSION=1.13.0.34 - ;; - 1.14) - VERSION=1.14.60.5 - ;; - 1.16) - VERSION=1.16.20.03 - ;; - 1.17) - VERSION=1.17.41.01 - ;; - 1.17.41) - VERSION=1.17.41.01 - ;; - 1.18|PREVIOUS) - VERSION=1.18.33.02 - ;; PREVIEW) echo "Looking up latest preview version..." lookupVersion serverBedrockPreviewLinux @@ -96,17 +92,13 @@ case ${VERSION^^} in ;; *) # use the given version exactly + echo "Using given version ${VERSION}" + lookupVersion serverBedrockLinux "${VERSION}" ;; esac if [[ ! -f "bedrock_server-${VERSION}" ]]; then - if [[ -z "${DOWNLOAD_URL}" ]]; then - binPath=bin-linux - isTrue "${PREVIEW}" && binPath+="-preview" - DOWNLOAD_URL="https://minecraft.azureedge.net/${binPath}/bedrock-server-${VERSION}.zip" - fi - [[ $TMP_DIR != /tmp ]] && mkdir -p "$TMP_DIR" TMP_ZIP="$TMP_DIR/$(basename "${DOWNLOAD_URL}")" From 5d6f3cc73598516a092e5fc5117378260213e98e Mon Sep 17 00:00:00 2001 From: thedhruvn <11063206+thedhruvn@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:00:21 -0500 Subject: [PATCH 2/2] patch: handle custom version with PREVIEW=true Old behavior: custom version only supported versioning for non-preview releases. New behavior: custom version can look up custom preview versions and custom release versions based on the value of the PREVIEW flag. --- bedrock-entry.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bedrock-entry.sh b/bedrock-entry.sh index 96377c6..c48214c 100755 --- a/bedrock-entry.sh +++ b/bedrock-entry.sh @@ -92,8 +92,13 @@ case ${VERSION^^} in ;; *) # use the given version exactly - echo "Using given version ${VERSION}" - lookupVersion serverBedrockLinux "${VERSION}" + if isTrue "$PREVIEW"; then + echo "Using given preview version ${VERSION}" + lookupVersion serverBedrockPreviewLinux "${VERSION}" + else + echo "Using given version ${VERSION}" + lookupVersion serverBedrockLinux "${VERSION}" + fi ;; esac