From 9fae57be3f254b4998392941732ce5d0fc11608c Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Mon, 20 Feb 2023 10:29:47 -0600 Subject: [PATCH] Added support for preview versions (#302) --- README.md | 9 +++-- bedrock-entry.sh | 86 +++++++++++++++++++++++++++++++----------------- 2 files changed, 62 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 34ce992..1bb8943 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,9 @@ docker run -d -it -e EULA=TRUE -p 19132:19132/udp -v mc-bedrock-data:/data itzg/ ## Upgrading to the latest Bedrock server version -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. +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. + +The latest preview version can be requested by setting `VERSION` to "PREVIEW". ## Looking for a Java Edition Server @@ -32,14 +34,15 @@ For Minecraft Java Edition you'll need to use this image instead: - `EULA` (no default) : must be set to `TRUE` to accept the [Minecraft End User License Agreement](https://minecraft.net/terms) - `VERSION` (`LATEST`) : can be set to a specific server version or the following special values can be used: - - `LATEST` : determines the latest version and can be used to auto-upgrade on container start + - `LATEST` : determines the latest (non-preview) version and can be used to auto-upgrade on container start + - `PREVIEW` : determines the latest preview version and will auto-upgrade - `PREVIOUS` : uses the previously maintained major version. Useful when the mobile app is gradually being upgraded across devices - `1.11` : the latest version of 1.11 - `1.12` : the latest version of 1.12 - `1.13` : the latest version of 1.13 - `1.14` : the latest version of 1.14 - `1.16` : the latest version of 1.16 - - otherwise any specific server version can be provided to allow for temporary bug avoidance, etc + - otherwise any specific server version can be provided. If it is a preview version, also set `PREVIEW` to "true" - `UID` (default derived from `/data` owner) : can be set to a specific user ID to run the bedrock server process - `GID` (default derived from `/data` owner) : can be set to a specific group ID to run the diff --git a/bedrock-entry.sh b/bedrock-entry.sh index e0b1342..0be1f75 100755 --- a/bedrock-entry.sh +++ b/bedrock-entry.sh @@ -3,6 +3,51 @@ set -eo pipefail : "${TMP_DIR:=/tmp}" +: "${PREVIEW:=false}" + +function isTrue() { + case "${1,,}" in + true | on | 1) + return 0 + ;; + *) + return 1 + ;; + esac +} + +function lookupVersion() { + platform=${1:?Missing required platform indicator} + + for i in {1..3}; do + 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 '') + if [[ ${DOWNLOAD_URL} ]]; then + break 2 + fi + sleep 1 + done + if [[ -z ${DOWNLOAD_URL} ]]; then + DOWNLOAD_URL=$(curl -s https://mc-bds-helper.vercel.app/api/latest) + fi + + if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then + VERSION=${BASH_REMATCH[1]} + elif [[ $(ls -rv bedrock_server-* 2> /dev/null|head -1) =~ bedrock_server-(.*) ]]; then + VERSION=${BASH_REMATCH[1]} + echo "WARN Minecraft download page failed, so using existing download of $VERSION" + cat restify.err + else + if [[ -f restify.err ]]; then + echo "Failed to extract download URL '${DOWNLOAD_URL}' from ${downloadPage}" + cat restify.err + rm restify.err + else + echo "Failed to lookup download URL: ${DOWNLOAD_URL}" + fi + exit 2 + fi + rm -f restify.err +} if [[ ${DEBUG^^} = TRUE ]]; then set -x @@ -45,36 +90,13 @@ case ${VERSION^^} in 1.18|PREVIOUS) VERSION=1.18.33.02 ;; + PREVIEW) + echo "Looking up latest preview version..." + lookupVersion serverBedrockPreviewLinux + ;; LATEST) echo "Looking up latest version..." - for i in {1..3}; do - 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 '') - if [[ ${DOWNLOAD_URL} ]]; then - break 2 - fi - sleep 1 - done - if [[ -z ${DOWNLOAD_URL} ]]; then - DOWNLOAD_URL=$(curl -s https://mc-bds-helper.vercel.app/api/latest) - fi - - if [[ ${DOWNLOAD_URL} =~ http.*/.*-(.*)\.zip ]]; then - VERSION=${BASH_REMATCH[1]} - elif [[ $(ls -rv bedrock_server-* 2> /dev/null|head -1) =~ bedrock_server-(.*) ]]; then - VERSION=${BASH_REMATCH[1]} - echo "WARN Minecraft download page failed, so using existing download of $VERSION" - cat restify.err - else - if [[ -f restify.err ]]; then - echo "Failed to extract download URL '${DOWNLOAD_URL}' from ${downloadPage}" - cat restify.err - rm restify.err - else - echo "Failed to lookup download URL: ${DOWNLOAD_URL}" - fi - exit 2 - fi - rm -f restify.err + lookupVersion serverBedrockLinux ;; *) # use the given version exactly @@ -84,14 +106,18 @@ esac if [ ! -f "bedrock_server-${VERSION}" ]; then if [[ ! ${DOWNLOAD_URL} ]]; then - DOWNLOAD_URL=https://minecraft.azureedge.net/bin-linux/bedrock-server-${VERSION}.zip + binPath=bin-linux + if isTrue "${PREVIEW}"; then + binPath=bin-linux-preview + fi + DOWNLOAD_URL="https://minecraft.azureedge.net/${binPath}/bedrock-server-${VERSION}.zip" fi [[ $TMP_DIR != /tmp ]] && mkdir -p "$TMP_DIR" TMP_ZIP="$TMP_DIR/$(basename "${DOWNLOAD_URL}")" echo "Downloading Bedrock server version ${VERSION} ..." - if ! curl "${curlArgs[@]}" -o ${TMP_ZIP} -fsSL ${DOWNLOAD_URL}; then + if ! curl "${curlArgs[@]}" -o "${TMP_ZIP}" -fsSL ${DOWNLOAD_URL}; then echo "ERROR failed to download from ${DOWNLOAD_URL}" echo " Double check that the given VERSION is valid" exit 2