From dfadf938cb3cfd5da32fcef4dbceae498092eafa Mon Sep 17 00:00:00 2001 From: Dhruv Narayanan Date: Thu, 17 Oct 2024 19:01:23 -0500 Subject: [PATCH] Fix: eliminated hardcoded URL for custom versions (#468) --- bedrock-entry.sh | 51 +++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/bedrock-entry.sh b/bedrock-entry.sh index 5ce9ba6..c48214c 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,18 @@ case ${VERSION^^} in ;; *) # use the given version exactly + if isTrue "$PREVIEW"; then + echo "Using given preview version ${VERSION}" + lookupVersion serverBedrockPreviewLinux "${VERSION}" + else + echo "Using given version ${VERSION}" + lookupVersion serverBedrockLinux "${VERSION}" + fi ;; 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}")"