Provide option to use existing bedrock server executable (#563)

This commit is contained in:
Geoff Bourne authored and GitHub committed 2025-10-27 22:12:47 -05:00
1 parent 41ef36c5f8
commit be0a795d98
2 files changed
+34 -6

No files matched your search

+1
View File
@@ -38,6 +38,7 @@ For Minecraft Java Edition you'll need to use this image instead:
- `VERSION` (default is `LATEST`) : can be set to a specific server version or the following special values can be used:
- `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
- `EXISTING`: use existing bedrock server executable in `/data`. Must be named either `bedrock_server-{version}` or just `bedrock_server`
- 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
+33 -6
View File
@@ -23,6 +23,20 @@ function replace_version_in_url() {
echo "$modified_url"
}
function versionFromExisting() {
# shellcheck disable=SC2012
# since find doesn't support sort by version numbers, -v
if [[ $(ls -rv bedrock_server-* 2> /dev/null|head -1) =~ bedrock_server-(.*) ]]; then
VERSION=${BASH_REMATCH[1]}
return 0
elif ls bedrock_server 2> /dev/null; then
VERSION=none
return 0
else
return 1
fi
}
function lookupVersion() {
platform=${1:?Missing required platform indicator}
customVersion=${2:-}
@@ -74,8 +88,7 @@ function lookupVersion() {
# shellcheck disable=SC2012
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]}
elif versionFromExisting; then
echo "WARN Minecraft download page failed, so using existing download of $VERSION"
else
echo "Failed to lookup download URL: ${DOWNLOAD_URL}"
@@ -128,6 +141,14 @@ else # Original logic: if DIRECT_DOWNLOAD_URL is NOT set, proceed with lookup
echo "Looking up latest version..."
lookupVersion serverBedrockLinux
;;
EXISTING)
if versionFromExisting; then
echo "Using existing bedrock server executable"
else
echo "ERROR unable to locate existing bedrock server executable"
exit 1
fi
;;
*)
# use the given version exactly
if isTrue "$PREVIEW"; then
@@ -141,7 +162,13 @@ else # Original logic: if DIRECT_DOWNLOAD_URL is NOT set, proceed with lookup
esac
fi
if [[ ! -f "bedrock_server-${VERSION}" ]]; then
if [[ $VERSION = none ]]; then
SERVER=bedrock_server
else
SERVER="bedrock_server-${VERSION}"
fi
if [[ ! -f "$SERVER" ]]; then
[[ $DOWNLOAD_DIR != /tmp ]] && mkdir -p "$DOWNLOAD_DIR"
TMP_ZIP="$DOWNLOAD_DIR/$(basename "${DOWNLOAD_URL}")"
@@ -199,7 +226,7 @@ if [[ ! -f "bedrock_server-${VERSION}" ]]; then
[[ $DOWNLOAD_DIR != /tmp ]] && rm -rf "$DOWNLOAD_DIR"
chmod +x bedrock_server
mv bedrock_server "bedrock_server-${VERSION}"
mv bedrock_server "$SERVER"
fi
if [[ -n "$OPS" || -n "$MEMBERS" || -n "$VISITORS" ]]; then
@@ -283,7 +310,7 @@ fi
echo "Starting Bedrock server..."
if [[ -f /usr/local/bin/box64 ]] ; then
exec mc-server-runner "${mcServerRunnerArgs[@]}" box64 ./"bedrock_server-${VERSION}"
exec mc-server-runner "${mcServerRunnerArgs[@]}" box64 ./"$SERVER"
else
exec mc-server-runner "${mcServerRunnerArgs[@]}" ./"bedrock_server-${VERSION}"
exec mc-server-runner "${mcServerRunnerArgs[@]}" ./"$SERVER"
fi