diff --git a/README.md b/README.md index cba30e01..71dc0952 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ By default, the container will download the latest version of the "vanilla" [Min * [Downloadable world](#downloadable-world) * [Cloning world from a container path](#cloning-world-from-a-container-path) * [Overwrite world on start](#overwrite-world-on-start) + * [Datapacks](#datapacks) * [Server configuration](#server-configuration) * [Message of the Day](#message-of-the-day) * [Difficulty](#difficulty) @@ -793,6 +794,16 @@ The following diagram shows how this option can be used in a compose deployment ### Overwrite world on start The world will only be downloaded or copied if it doesn't exist already. Set `FORCE_WORLD_COPY=TRUE` to force overwrite the world on every server start. +### Datapacks +Datapacks can be installed in a similar manner to mods/plugins. There are many environment variables which function in the same way they do for [mods](#working-with-mods-and-plugins): +* `DATAPACKS` +* `DATAPACKS_FILE` +* `REMOVE_OLD_DATAPACKS` +* `REMOVE_OLD_DATAPACKS_DEPTH` +* `REMOVE_OLD_DATAPACKS_INCLUDE` +* `REMOVE_OLD_DATAPACKS_EXCLUDE` +Datapacks will be placed in `/data/$LEVEL/datapacks` + ## Server configuration By default, the server configuration will be created and set based on the following environment variables, but only the first time the server is started. If the `server.properties` file already exists, the values in them will not be changed. diff --git a/scripts/start-setupDatapack b/scripts/start-setupDatapack new file mode 100755 index 00000000..b8134191 --- /dev/null +++ b/scripts/start-setupDatapack @@ -0,0 +1,77 @@ +#!/bin/bash + +set -e -o pipefail + +: "${REMOVE_OLD_DATAPACKS:=false}" +: "${DATAPACKS_FILE:=}" +: "${REMOVE_OLD_DATAPACKS_DEPTH:=1} " +: "${REMOVE_OLD_DATAPACKS_INCLUDE:=*.zip}" + +# shellcheck source=start-utils +. "${SCRIPTS:-/}start-utils" +isDebugging && set -x + +out_dir=/data/${LEVEL:-world}/datapacks + +# Remove old datapacks +if isTrue "${REMOVE_OLD_DATAPACKS}" && [ -z "${DATAPACKS_FILE}" ]; then + if [ -d "$out_dir" ]; then + find "$out_dir" -mindepth 1 -maxdepth ${REMOVE_OLD_DATAPACKS_DEPTH:-16} -wholename "${REMOVE_OLD_DATAPACKS_INCLUDE:-*}" -not -wholename "${REMOVE_OLD_DATAPACKS_EXCLUDE:-}" -delete + fi +fi + +if [[ "$DATAPACKS" ]]; then + mkdir -p "$out_dir" + + for i in ${DATAPACKS//,/ } + do + if isURL "$i"; then + log "Downloading datapack $i ..." + if ! get -o "${out_dir}" "$i"; then + log "ERROR: failed to download from $i into $out_dir" + exit 2 + fi + elif [[ -f "$i" && "$i" =~ .*\.zip ]]; then + log "Copying datapack located at $i ..." + out_file=$(basename "$i") + if ! cp "$i" "${out_dir}/$out_file"; then + log "ERROR: failed to copy from $i into $out_dir" + exit 2 + fi + elif [[ -d "$i" ]]; then + log "Copying datapacks from $i ..." + cp "$i"/*.zip "${out_dir}" + else + log "ERROR Invalid URL or path given in DATAPACKS: $i" + exit 2 + fi + done + +elif [[ "$DATAPACKS_FILE" ]]; then + if [ ! -f "$DATAPACKS_FILE" ]; then + log "ERROR: given DATAPACKS_FILE file does not exist" + exit 2 + fi + + mkdir -p "$out_dir" + + args=( + -o "${out_dir}" + --log-progress-each + --skip-existing + --uris-file "${DATAPACKS_FILE}" + ) + if isTrue "${REMOVE_OLD_DATAPACKS}"; then + args+=( + --prune-others "${REMOVE_OLD_DATAPACKS_INCLUDE}" + --prune-depth "${REMOVE_OLD_DATAPACKS_DEPTH}" + ) + fi + + if ! get "${args[@]}" ; then + log "ERROR: failed to retrieve one or more datapacks" + exit 1 + fi +fi + +exec "${SCRIPTS:-/}start-setupModpack" "$@" diff --git a/scripts/start-setupWorld b/scripts/start-setupWorld index d2803f7c..3484b46d 100755 --- a/scripts/start-setupWorld +++ b/scripts/start-setupWorld @@ -69,4 +69,4 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] ); fi fi -exec "${SCRIPTS:-/}start-setupModpack" "$@" +exec "${SCRIPTS:-/}start-setupDatapack" "$@"