Skip to content

Commit 1369abe

Browse files
authored
Update to use new Minecraft API for download URL instead of restify (#525)
1 parent de15d69 commit 1369abe

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

bedrock-entry.sh

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,41 @@ function replace_version_in_url() {
2323

2424
function lookupVersion() {
2525
platform=${1:?Missing required platform indicator}
26-
customVersion=${2:-}
27-
28-
# shellcheck disable=SC2034
29-
for i in {1..3}; do
30-
DOWNLOAD_URL=$(restify --user-agent=itzg/minecraft-bedrock-server --headers "accept-language:*" --attribute=data-platform="${platform}" "${downloadPage}" 2> restify.err | jq -r '.[0].href' || echo '')
31-
[[ -n "${DOWNLOAD_URL}" ]] && break
32-
sleep 1
33-
done
34-
if [[ -z ${DOWNLOAD_URL} ]]; then
35-
DOWNLOAD_URL=$(curl -s https://mc-bds-helper.vercel.app/api/latest)
36-
fi
37-
38-
if [[ -n "${customVersion}" && -n "${DOWNLOAD_URL}" ]]; then
39-
DOWNLOAD_URL=$(replace_version_in_url "${DOWNLOAD_URL}" "${customVersion}")
40-
return
41-
fi
26+
# TODO need to find out API call to lookup custom version
27+
# customVersion=${2:-}
28+
29+
DOWNLOAD_URL=$(
30+
curl -fsSL "${getUrlPage}" |
31+
jq --arg platform serverBedrockLinux -rR '
32+
try(fromjson) catch({}) |
33+
.result.links // halt_error(1) |
34+
map(
35+
select(.downloadType == $platform)
36+
) |
37+
if length > 0 then
38+
first |
39+
.downloadUrl
40+
else
41+
(
42+
"Error: could not find platform (\($platform))\n" |
43+
stderr |
44+
"" |
45+
halt_error(2)
46+
)
47+
end
48+
'
49+
)
4250

4351
# shellcheck disable=SC2012
4452
if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then
4553
VERSION=${BASH_REMATCH[1]}
4654
elif [[ $(ls -rv bedrock_server-* 2> /dev/null|head -1) =~ bedrock_server-(.*) ]]; then
4755
VERSION=${BASH_REMATCH[1]}
4856
echo "WARN Minecraft download page failed, so using existing download of $VERSION"
49-
cat restify.err
5057
else
51-
if [[ -f restify.err ]]; then
52-
echo "Failed to extract download URL '${DOWNLOAD_URL}' from ${downloadPage}"
53-
cat restify.err
54-
rm restify.err
55-
else
56-
echo "Failed to lookup download URL: ${DOWNLOAD_URL}"
57-
fi
58+
echo "Failed to lookup download URL: ${DOWNLOAD_URL}"
5859
exit 2
5960
fi
60-
rm -f restify.err
6161
}
6262

6363
if [[ ${DEBUG^^} == TRUE ]]; then
@@ -69,7 +69,8 @@ fi
6969

7070
export HOME="${PWD}"
7171

72-
downloadPage=https://www.minecraft.net/en-us/download/server/bedrock
72+
# Looks like both net and net-secondary hostnames work
73+
getUrlPage=https://net-secondary.web.minecraft-services.net/api/v1.0/download/links
7374

7475
if [[ ${EULA^^} != TRUE ]]; then
7576
echo

0 commit comments

Comments
 (0)