Skip to content

Commit 9fae57b

Browse files
authored
Added support for preview versions (#302)
1 parent 1ba7b84 commit 9fae57b

File tree

2 files changed

+62
-33
lines changed

2 files changed

+62
-33
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ docker run -d -it -e EULA=TRUE -p 19132:19132/udp -v mc-bedrock-data:/data itzg/
1717
1818
## Upgrading to the latest Bedrock server version
1919

20-
With the `VERSION` variable set to `LATEST`, which is the default, then the Bedrock server can be upgraded by restarting the container. At every startup, the container checks for the latest version and upgrades, if needed.
20+
With the `VERSION` variable set to "LATEST", which is the default, then the Bedrock server can be upgraded by restarting the container. At every startup, the container checks for the latest version and upgrades, if needed.
21+
22+
The latest preview version can be requested by setting `VERSION` to "PREVIEW".
2123

2224
## Looking for a Java Edition Server
2325

@@ -32,14 +34,15 @@ For Minecraft Java Edition you'll need to use this image instead:
3234
- `EULA` (no default) : must be set to `TRUE` to
3335
accept the [Minecraft End User License Agreement](https://minecraft.net/terms)
3436
- `VERSION` (`LATEST`) : can be set to a specific server version or the following special values can be used:
35-
- `LATEST` : determines the latest version and can be used to auto-upgrade on container start
37+
- `LATEST` : determines the latest (non-preview) version and can be used to auto-upgrade on container start
38+
- `PREVIEW` : determines the latest preview version and will auto-upgrade
3639
- `PREVIOUS` : uses the previously maintained major version. Useful when the mobile app is gradually being upgraded across devices
3740
- `1.11` : the latest version of 1.11
3841
- `1.12` : the latest version of 1.12
3942
- `1.13` : the latest version of 1.13
4043
- `1.14` : the latest version of 1.14
4144
- `1.16` : the latest version of 1.16
42-
- otherwise any specific server version can be provided to allow for temporary bug avoidance, etc
45+
- otherwise any specific server version can be provided. If it is a preview version, also set `PREVIEW` to "true"
4346
- `UID` (default derived from `/data` owner) : can be set to a specific user ID to run the
4447
bedrock server process
4548
- `GID` (default derived from `/data` owner) : can be set to a specific group ID to run the

bedrock-entry.sh

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,51 @@
33
set -eo pipefail
44

55
: "${TMP_DIR:=/tmp}"
6+
: "${PREVIEW:=false}"
7+
8+
function isTrue() {
9+
case "${1,,}" in
10+
true | on | 1)
11+
return 0
12+
;;
13+
*)
14+
return 1
15+
;;
16+
esac
17+
}
18+
19+
function lookupVersion() {
20+
platform=${1:?Missing required platform indicator}
21+
22+
for i in {1..3}; do
23+
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 '')
24+
if [[ ${DOWNLOAD_URL} ]]; then
25+
break 2
26+
fi
27+
sleep 1
28+
done
29+
if [[ -z ${DOWNLOAD_URL} ]]; then
30+
DOWNLOAD_URL=$(curl -s https://mc-bds-helper.vercel.app/api/latest)
31+
fi
32+
33+
if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then
34+
VERSION=${BASH_REMATCH[1]}
35+
elif [[ $(ls -rv bedrock_server-* 2> /dev/null|head -1) =~ bedrock_server-(.*) ]]; then
36+
VERSION=${BASH_REMATCH[1]}
37+
echo "WARN Minecraft download page failed, so using existing download of $VERSION"
38+
cat restify.err
39+
else
40+
if [[ -f restify.err ]]; then
41+
echo "Failed to extract download URL '${DOWNLOAD_URL}' from ${downloadPage}"
42+
cat restify.err
43+
rm restify.err
44+
else
45+
echo "Failed to lookup download URL: ${DOWNLOAD_URL}"
46+
fi
47+
exit 2
48+
fi
49+
rm -f restify.err
50+
}
651

752
if [[ ${DEBUG^^} = TRUE ]]; then
853
set -x
@@ -45,36 +90,13 @@ case ${VERSION^^} in
4590
1.18|PREVIOUS)
4691
VERSION=1.18.33.02
4792
;;
93+
PREVIEW)
94+
echo "Looking up latest preview version..."
95+
lookupVersion serverBedrockPreviewLinux
96+
;;
4897
LATEST)
4998
echo "Looking up latest version..."
50-
for i in {1..3}; do
51-
DOWNLOAD_URL=$(restify --user-agent=itzg/minecraft-bedrock-server --headers "accept-language:*" --attribute=data-platform=serverBedrockLinux ${downloadPage} 2> restify.err | jq -r '.[0].href' || echo '')
52-
if [[ ${DOWNLOAD_URL} ]]; then
53-
break 2
54-
fi
55-
sleep 1
56-
done
57-
if [[ -z ${DOWNLOAD_URL} ]]; then
58-
DOWNLOAD_URL=$(curl -s https://mc-bds-helper.vercel.app/api/latest)
59-
fi
60-
61-
if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then
62-
VERSION=${BASH_REMATCH[1]}
63-
elif [[ $(ls -rv bedrock_server-* 2> /dev/null|head -1) =~ bedrock_server-(.*) ]]; then
64-
VERSION=${BASH_REMATCH[1]}
65-
echo "WARN Minecraft download page failed, so using existing download of $VERSION"
66-
cat restify.err
67-
else
68-
if [[ -f restify.err ]]; then
69-
echo "Failed to extract download URL '${DOWNLOAD_URL}' from ${downloadPage}"
70-
cat restify.err
71-
rm restify.err
72-
else
73-
echo "Failed to lookup download URL: ${DOWNLOAD_URL}"
74-
fi
75-
exit 2
76-
fi
77-
rm -f restify.err
99+
lookupVersion serverBedrockLinux
78100
;;
79101
*)
80102
# use the given version exactly
@@ -84,14 +106,18 @@ esac
84106
if [ ! -f "bedrock_server-${VERSION}" ]; then
85107

86108
if [[ ! ${DOWNLOAD_URL} ]]; then
87-
DOWNLOAD_URL=https://minecraft.azureedge.net/bin-linux/bedrock-server-${VERSION}.zip
109+
binPath=bin-linux
110+
if isTrue "${PREVIEW}"; then
111+
binPath=bin-linux-preview
112+
fi
113+
DOWNLOAD_URL="https://minecraft.azureedge.net/${binPath}/bedrock-server-${VERSION}.zip"
88114
fi
89115

90116
[[ $TMP_DIR != /tmp ]] && mkdir -p "$TMP_DIR"
91117
TMP_ZIP="$TMP_DIR/$(basename "${DOWNLOAD_URL}")"
92118

93119
echo "Downloading Bedrock server version ${VERSION} ..."
94-
if ! curl "${curlArgs[@]}" -o ${TMP_ZIP} -fsSL ${DOWNLOAD_URL}; then
120+
if ! curl "${curlArgs[@]}" -o "${TMP_ZIP}" -fsSL ${DOWNLOAD_URL}; then
95121
echo "ERROR failed to download from ${DOWNLOAD_URL}"
96122
echo " Double check that the given VERSION is valid"
97123
exit 2

0 commit comments

Comments
 (0)