@@ -23,41 +23,41 @@ function replace_version_in_url() {
23
23
24
24
function lookupVersion() {
25
25
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
+ )
42
50
43
51
# shellcheck disable=SC2012
44
52
if [[ ${DOWNLOAD_URL} =~ http.* /.* -(.* )\. zip ]]; then
45
53
VERSION=${BASH_REMATCH[1]}
46
54
elif [[ $( ls -rv bedrock_server-* 2> /dev/null| head -1) =~ bedrock_server-(.* ) ]]; then
47
55
VERSION=${BASH_REMATCH[1]}
48
56
echo " WARN Minecraft download page failed, so using existing download of $VERSION "
49
- cat restify.err
50
57
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} "
58
59
exit 2
59
60
fi
60
- rm -f restify.err
61
61
}
62
62
63
63
if [[ ${DEBUG^^} == TRUE ]]; then
69
69
70
70
export HOME=" ${PWD} "
71
71
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
73
74
74
75
if [[ ${EULA^^} != TRUE ]]; then
75
76
echo
0 commit comments