Skip to content

Commit 7a27256

Browse files
committed
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
1 parent a5b46e5 commit 7a27256

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

bedrock-entry.sh

+19-27
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,20 @@ function isTrue() {
1010
return 1
1111
}
1212

13+
function replace_version_in_url() {
14+
local original_url="$1"
15+
local new_version="$2"
16+
17+
# Use sed to replace the version number in the URL
18+
local modified_url
19+
modified_url=$(echo "$original_url" | sed -E "s/(bedrock-server-)[^/]+(\.zip)/\1${new_version}\2/")
20+
21+
echo "$modified_url"
22+
}
23+
1324
function lookupVersion() {
1425
platform=${1:?Missing required platform indicator}
26+
customVersion=${2:-}
1527

1628
# shellcheck disable=SC2034
1729
for i in {1..3}; do
@@ -23,6 +35,11 @@ function lookupVersion() {
2335
DOWNLOAD_URL=$(curl -s https://mc-bds-helper.vercel.app/api/latest)
2436
fi
2537

38+
if [[ -n "${customVersion}" && -n "${DOWNLOAD_URL}" ]]; then
39+
DOWNLOAD_URL=$(replace_version_in_url "${DOWNLOAD_URL}" "${customVersion}")
40+
return
41+
fi
42+
2643
# shellcheck disable=SC2012
2744
if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then
2845
VERSION=${BASH_REMATCH[1]}
@@ -65,27 +82,6 @@ if [[ ${EULA^^} != TRUE ]]; then
6582
fi
6683

6784
case ${VERSION^^} in
68-
1.12)
69-
VERSION=1.12.0.28
70-
;;
71-
1.13)
72-
VERSION=1.13.0.34
73-
;;
74-
1.14)
75-
VERSION=1.14.60.5
76-
;;
77-
1.16)
78-
VERSION=1.16.20.03
79-
;;
80-
1.17)
81-
VERSION=1.17.41.01
82-
;;
83-
1.17.41)
84-
VERSION=1.17.41.01
85-
;;
86-
1.18|PREVIOUS)
87-
VERSION=1.18.33.02
88-
;;
8985
PREVIEW)
9086
echo "Looking up latest preview version..."
9187
lookupVersion serverBedrockPreviewLinux
@@ -96,17 +92,13 @@ case ${VERSION^^} in
9692
;;
9793
*)
9894
# use the given version exactly
95+
echo "Using given version ${VERSION}"
96+
lookupVersion serverBedrockLinux "${VERSION}"
9997
;;
10098
esac
10199

102100
if [[ ! -f "bedrock_server-${VERSION}" ]]; then
103101

104-
if [[ -z "${DOWNLOAD_URL}" ]]; then
105-
binPath=bin-linux
106-
isTrue "${PREVIEW}" && binPath+="-preview"
107-
DOWNLOAD_URL="https://minecraft.azureedge.net/${binPath}/bedrock-server-${VERSION}.zip"
108-
fi
109-
110102
[[ $TMP_DIR != /tmp ]] && mkdir -p "$TMP_DIR"
111103
TMP_ZIP="$TMP_DIR/$(basename "${DOWNLOAD_URL}")"
112104

0 commit comments

Comments
 (0)