Add MC_PACK support (with FORCE_WORLD_COPY & FORCE_PACK_COPY) (#606)
This commit is contained in:
2 files changed
+73
No files matched your search
@@ -48,6 +48,9 @@ For Minecraft Java Edition you'll need to use this image instead:
|
|||||||
- `PACKAGE_BACKUP_KEEP` (`2`) : how many package backups to keep
|
- `PACKAGE_BACKUP_KEEP` (`2`) : how many package backups to keep
|
||||||
- `DIRECT_DOWNLOAD_URL` (no default): This environment variable can be used to provide a **direct download URL** for the Minecraft Bedrock server `.zip` file. When set, this URL will be used instead of attempting to automatically look up the download link from `minecraft.net`. This is particularly useful for CI/CD environments or when the automatic version lookup is temporarily broken due to website changes. Ensure the URL points directly to the `bedrock-server-VERSION.zip` file.
|
- `DIRECT_DOWNLOAD_URL` (no default): This environment variable can be used to provide a **direct download URL** for the Minecraft Bedrock server `.zip` file. When set, this URL will be used instead of attempting to automatically look up the download link from `minecraft.net`. This is particularly useful for CI/CD environments or when the automatic version lookup is temporarily broken due to website changes. Ensure the URL points directly to the `bedrock-server-VERSION.zip` file.
|
||||||
- `ENABLE_SSH` (default is `false`) : Enable remote console over SSH on port 2222 if this environment variable is set to `true`.
|
- `ENABLE_SSH` (default is `false`) : Enable remote console over SSH on port 2222 if this environment variable is set to `true`.
|
||||||
|
- `MC_PACK` (no default): Path inside the container to a single archive file (e.g. `.mcpack`, `.mcworld`, `.mctemplate`, `.mcaddon`, or any zip) or to a directory with the same layout. At startup the archive is unpacked (or the directory is read): top-level `behavior_packs/` is merged into `behavior_packs/`, top-level `resource_packs/` into `resource_packs/`, and all other content (when `level.dat` is present) into `worlds/{LEVEL_NAME}`. For `.mcaddon` archives, which use root-level `data/` (behavior) and `resources/` (resource) folders instead of `behavior_packs/` and `resource_packs/`, these are detected and installed automatically using the pack UUID from each manifest as the folder name.
|
||||||
|
- `FORCE_WORLD_COPY` (default `false`): When `MC_PACK` contains a world (`level.dat`), set to `true` to remove and replace the existing `worlds/{LEVEL_NAME}` on every startup; otherwise the world is copied only when it does not exist.
|
||||||
|
- `FORCE_PACK_COPY` (default `false`): When `MC_PACK` contains `behavior_packs/` or `resource_packs/`, set to `true` to remove and replace existing pack folders with the same name on every startup; otherwise each pack is copied only when it does not already exist.
|
||||||
|
|
||||||
|
|
||||||
### Server Properties
|
### Server Properties
|
||||||
@@ -226,6 +229,8 @@ All variables are written to the variables file located at `config/default/varia
|
|||||||
|
|
||||||
Also known as behavior or resource packs, in order to add mods into your server you can follow these steps, tested with [OPS (One Player Sleep)](https://foxynotail.com/addons/ops/) and [bedrocktweaks](https://bedrocktweaks.net/resource-packs/)
|
Also known as behavior or resource packs, in order to add mods into your server you can follow these steps, tested with [OPS (One Player Sleep)](https://foxynotail.com/addons/ops/) and [bedrocktweaks](https://bedrocktweaks.net/resource-packs/)
|
||||||
|
|
||||||
|
> **Tip:** You can import an archive at startup by setting `MC_PACK` to the in-container path (see [Environment Variables](#environment-variables)). The archive is unpacked: `behavior_packs/` and `resource_packs/` go to the server's pack folders; if the archive contains a world (`level.dat`), the rest goes to `worlds/{LEVEL_NAME}`.
|
||||||
|
|
||||||
1. Install the mcpack or mcaddon on the client side first, just to make it easier to copy the files to the server, for Windows 10 files should be located on `C:\Users\USER\AppData\Local\Packages\Microsoft.MinecraftUWP_*\LocalState\games\com.mojang`.
|
1. Install the mcpack or mcaddon on the client side first, just to make it easier to copy the files to the server, for Windows 10 files should be located on `C:\Users\USER\AppData\Local\Packages\Microsoft.MinecraftUWP_*\LocalState\games\com.mojang`.
|
||||||
2. Copy over the folders of the mods from either behavior_packs or resource_packs into the server's volume.
|
2. Copy over the folders of the mods from either behavior_packs or resource_packs into the server's volume.
|
||||||
> If you want to install them without using a client you should be able to unzip the mods directly into the server's volume, .mcaddon should go into behavior_packs and .mcpack into resource_packs. Both .mcaddon and .mcpack are actually renamed .zip files.
|
> If you want to install them without using a client you should be able to unzip the mods directly into the server's volume, .mcaddon should go into behavior_packs and .mcpack into resource_packs. Both .mcaddon and .mcpack are actually renamed .zip files.
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ set -eo pipefail
|
|||||||
: "${DOWNLOAD_SECONDARY_LINKS_URL:=https://net-secondary.web.minecraft-services.net/api/v1.0/download/links}"
|
: "${DOWNLOAD_SECONDARY_LINKS_URL:=https://net-secondary.web.minecraft-services.net/api/v1.0/download/links}"
|
||||||
: "${USE_BOX64:=true}"
|
: "${USE_BOX64:=true}"
|
||||||
: "${DEBUG_CURL:=false}"
|
: "${DEBUG_CURL:=false}"
|
||||||
|
: "${FORCE_PACK_COPY:=false}"
|
||||||
|
: "${FORCE_WORLD_COPY:=false}"
|
||||||
|
: "${LEVEL_NAME:=Bedrock level}"
|
||||||
|
|
||||||
function isTrue() {
|
function isTrue() {
|
||||||
[[ "${1,,}" =~ ^(true|on|1)$ ]] && return 0
|
[[ "${1,,}" =~ ^(true|on|1)$ ]] && return 0
|
||||||
@@ -109,6 +112,8 @@ if [[ ${DEBUG^^} == TRUE ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
export HOME="${PWD}"
|
export HOME="${PWD}"
|
||||||
|
export TMPDIR="${HOME}/.tmp"
|
||||||
|
mkdir -p "${TMPDIR}"
|
||||||
|
|
||||||
if [[ ${EULA^^} != TRUE ]]; then
|
if [[ ${EULA^^} != TRUE ]]; then
|
||||||
echo
|
echo
|
||||||
@@ -249,6 +254,69 @@ if [[ ! -f "$SERVER" ]]; then
|
|||||||
mv bedrock_server "$SERVER"
|
mv bedrock_server "$SERVER"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -n "${MC_PACK:-}" ]]; then
|
||||||
|
if [[ -d "$MC_PACK" ]]; then
|
||||||
|
srcDir="$MC_PACK"
|
||||||
|
cleanupTmp=
|
||||||
|
elif [[ -f "$MC_PACK" ]]; then
|
||||||
|
srcDir=$(mktemp -d)
|
||||||
|
cleanupTmp=1
|
||||||
|
unzip -q -o "$MC_PACK" -d "$srcDir"
|
||||||
|
else
|
||||||
|
logWarn "MC_PACK is set but path does not exist or is not a file/directory: $MC_PACK"
|
||||||
|
srcDir=
|
||||||
|
fi
|
||||||
|
if [[ -n "$srcDir" ]]; then
|
||||||
|
if [[ ! -d "$srcDir/behavior_packs" && ! -d "$srcDir/resource_packs" ]] && \
|
||||||
|
[[ -f "$srcDir/data/manifest.json" || -f "$srcDir/resources/manifest.json" ]]; then
|
||||||
|
for subdir in data resources; do
|
||||||
|
packManifestFile="$srcDir/$subdir/manifest.json"
|
||||||
|
[[ -f "$packManifestFile" ]] || continue
|
||||||
|
|
||||||
|
packId=$(jq -r '.header.uuid' "$packManifestFile")
|
||||||
|
destName="behavior_packs"; [[ "$subdir" == "resources" ]] && destName="resource_packs"
|
||||||
|
|
||||||
|
worldPacksFile="$srcDir/world_${destName}.json"
|
||||||
|
worldPacksJson=$(jq -c '[{pack_id: .header.uuid, version: .header.version}]' "$packManifestFile")
|
||||||
|
|
||||||
|
mkdir -p "$srcDir/$destName"
|
||||||
|
mv "$srcDir/$subdir" "$srcDir/$destName/$packId"
|
||||||
|
echo "$worldPacksJson" > "$worldPacksFile" && echo "Generated $worldPacksFile as $worldPacksJson"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
for dir in behavior_packs resource_packs; do
|
||||||
|
if [[ -d "$srcDir/$dir" ]]; then
|
||||||
|
mkdir -p "$dir"
|
||||||
|
for sub in "$srcDir/$dir"/*; do
|
||||||
|
destSub="$dir/$(basename "$sub")"
|
||||||
|
if isTrue "$FORCE_PACK_COPY" && [[ -d "$destSub" ]]; then
|
||||||
|
logWarn "Removing existing pack at $destSub (FORCE_PACK_COPY=TRUE)"
|
||||||
|
rm -rf "$destSub"
|
||||||
|
fi
|
||||||
|
[[ ! -d "$destSub" ]] && echo "Copying pack $(basename "$sub") to $dir" && cp -a "$sub" "$dir/"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
levelDir="worlds/$LEVEL_NAME"
|
||||||
|
if [[ -f "$srcDir/level.dat" ]]; then
|
||||||
|
if isTrue "$FORCE_WORLD_COPY" || [[ ! -f "$levelDir/level.dat" ]]; then
|
||||||
|
if isTrue "$FORCE_WORLD_COPY" && [[ -d "$levelDir" ]]; then
|
||||||
|
logWarn "Removing existing world at $levelDir (FORCE_WORLD_COPY=TRUE)"
|
||||||
|
rm -rf "$levelDir"
|
||||||
|
fi
|
||||||
|
for item in "$srcDir"/*; do
|
||||||
|
name=$(basename "$item")
|
||||||
|
[[ "$name" == "behavior_packs" || "$name" == "resource_packs" ]] && continue
|
||||||
|
mkdir -p "$levelDir"
|
||||||
|
echo "Copying world item $name to $levelDir"
|
||||||
|
cp -a "$item" "$levelDir/"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
[[ -n "$cleanupTmp" ]] && rm -rf "$srcDir"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -n "$OPS" || -n "$MEMBERS" || -n "$VISITORS" ]]; then
|
if [[ -n "$OPS" || -n "$MEMBERS" || -n "$VISITORS" ]]; then
|
||||||
echo "Updating permissions"
|
echo "Updating permissions"
|
||||||
jq -n --arg ops "$OPS" --arg members "$MEMBERS" --arg visitors "$VISITORS" '[
|
jq -n --arg ops "$OPS" --arg members "$MEMBERS" --arg visitors "$VISITORS" '[
|
||||||
|
|||||||
Reference in new issue
Block a user