Skip to content

Commit dfadf93

Browse files
authored
Fix: eliminated hardcoded URL for custom versions (#468)
1 parent a5b46e5 commit dfadf93

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

bedrock-entry.sh

Lines changed: 24 additions & 27 deletions
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,18 @@ case ${VERSION^^} in
9692
;;
9793
*)
9894
# use the given version exactly
95+
if isTrue "$PREVIEW"; then
96+
echo "Using given preview version ${VERSION}"
97+
lookupVersion serverBedrockPreviewLinux "${VERSION}"
98+
else
99+
echo "Using given version ${VERSION}"
100+
lookupVersion serverBedrockLinux "${VERSION}"
101+
fi
99102
;;
100103
esac
101104

102105
if [[ ! -f "bedrock_server-${VERSION}" ]]; then
103106

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-
110107
[[ $TMP_DIR != /tmp ]] && mkdir -p "$TMP_DIR"
111108
TMP_ZIP="$TMP_DIR/$(basename "${DOWNLOAD_URL}")"
112109

0 commit comments

Comments
 (0)