Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: eliminated hardcoded URL for custom versions #468

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions bedrock-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]}
Expand Down Expand Up @@ -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
Expand All @@ -96,17 +92,18 @@ case ${VERSION^^} in
;;
*)
# use the given version exactly
if isTrue "$PREVIEW"; then
itzg marked this conversation as resolved.
Show resolved Hide resolved
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"
itzg marked this conversation as resolved.
Show resolved Hide resolved
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}")"

Expand Down
Loading