diff --git a/docs/mods-and-plugins/index.md b/docs/mods-and-plugins/index.md index f021295f..e0553da1 100644 --- a/docs/mods-and-plugins/index.md +++ b/docs/mods-and-plugins/index.md @@ -66,6 +66,8 @@ You can also specify the `REMOVE_OLD_MODS_DEPTH` (default is 16) variable to onl For example: `-e REMOVE_OLD_MODS=TRUE -e REMOVE_OLD_MODS_INCLUDE="*.jar" -e REMOVE_OLD_MODS_DEPTH=1` will remove all old jar files that are directly inside the `plugins/` or `mods/` directory. +To remove all files in the `/data/config` directory before a modpack is downloaded and unpacked, set `REMOVE_OLD_CONFIGS=TRUE`. This is useful when a modpack update would otherwise override locally customized configuration files. The removal process can be fine tuned with `REMOVE_OLD_CONFIGS_INCLUDE` and `REMOVE_OLD_CONFIGS_EXCLUDE` (comma separated lists of file glob patterns, defaults to `*` so everything is removed) and `REMOVE_OLD_CONFIGS_DEPTH` (default 16). The target directory can be changed with `CONFIG_OUT_DIR` (default `/data/config`). + These paths work well if you want to have a common set of modules in a separate location, but still have multiple worlds with different server requirements in either persistent volumes or a downloadable archive. !!! information "Multiple source directories" diff --git a/scripts/start-setupModpack b/scripts/start-setupModpack index a36c8f86..9c8215b4 100755 --- a/scripts/start-setupModpack +++ b/scripts/start-setupModpack @@ -9,6 +9,11 @@ set -e -o pipefail : "${PLUGINS_FILE:=}" : "${REMOVE_OLD_MODS_DEPTH:=1} " : "${REMOVE_OLD_MODS_INCLUDE:=*.jar,*-version.json}" +: "${REMOVE_OLD_CONFIGS:=false}" +: "${CONFIG_OUT_DIR:=/data/config}" +: "${REMOVE_OLD_CONFIGS_DEPTH:=16}" +: "${REMOVE_OLD_CONFIGS_INCLUDE:=*}" +: "${REMOVE_OLD_CONFIGS_EXCLUDE:=}" : "${CF_USE_HTTP2:=false}" # CF downloads are faster with HTTP 1.1 : "${MODRINTH_LOADER:=}" @@ -25,6 +30,10 @@ if isTrue "${REMOVE_OLD_MODS}" && [ -z "${MODS_FILE}" ]; then rm -f "$sum_file" fi +if isTrue "${REMOVE_OLD_CONFIGS}"; then + removeOldConfigs "$CONFIG_OUT_DIR" +fi + function handlePackwiz() { # If packwiz url passed, bootstrap packwiz and update mods before other modpack processing if [[ "${PACKWIZ_URL:-}" ]]; then diff --git a/scripts/start-utils b/scripts/start-utils index 71b66390..7db9977b 100755 --- a/scripts/start-utils +++ b/scripts/start-utils @@ -547,6 +547,23 @@ function removeOldMods { fi } +function removeOldConfigs { + if [ -d "$1" ]; then + log "Removing old configs including='${REMOVE_OLD_CONFIGS_INCLUDE}' excluding='${REMOVE_OLD_CONFIGS_EXCLUDE}' up to depth=${REMOVE_OLD_CONFIGS_DEPTH}" + args=( + --delete + --type file + --min-depth=1 --max-depth "${REMOVE_OLD_CONFIGS_DEPTH}" + --name "${REMOVE_OLD_CONFIGS_INCLUDE}" + --exclude-name "${REMOVE_OLD_CONFIGS_EXCLUDE}" + ) + if ! isDebugging; then + args+=(--quiet) + fi + mc-image-helper find "${args[@]}" "$1" + fi +} + function get() { mc-image-helper get "$@" } diff --git a/tests/setuponlytests/remove-old-configs/configs.zip b/tests/setuponlytests/remove-old-configs/configs.zip new file mode 100644 index 00000000..5e30e0a4 Binary files /dev/null and b/tests/setuponlytests/remove-old-configs/configs.zip differ diff --git a/tests/setuponlytests/remove-old-configs/docker-compose.yml b/tests/setuponlytests/remove-old-configs/docker-compose.yml new file mode 100644 index 00000000..aa136e67 --- /dev/null +++ b/tests/setuponlytests/remove-old-configs/docker-compose.yml @@ -0,0 +1,43 @@ +services: + # copies an existing config into /data before mc starts, so REMOVE_OLD_CONFIGS + # has an old config to remove once the modpack config is installed + seed: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + entrypoint: ["bash", "-c", "mkdir -p /data/config && cp /seed/config/stale.txt /data/config/ && chown -R 1000:1000 /data"] + volumes: + - ./seed:/seed + - ./data:/data + + web: + image: nginx + volumes: + - ./configs.zip:/usr/share/nginx/html/configs.zip:ro + healthcheck: + test: ["CMD", "curl", "--fail", "http://localhost/configs.zip"] + interval: 3s + timeout: 5s + retries: 3 + + mc: + restart: "no" + image: ${IMAGE_TO_TEST:-itzg/minecraft-server} + depends_on: + seed: + condition: service_completed_successfully + web: + condition: service_healthy + environment: + EULA: "true" + SETUP_ONLY: "true" + GENERIC_PACKS: http://web/configs.zip + REMOVE_OLD_CONFIGS: "true" + LOG_TIMESTAMP: "true" + # the following are only used to speed up test execution + TYPE: CUSTOM + CUSTOM_SERVER: /servers/fake.jar + VERSION: 1.18.1 + DEBUG: "true" + volumes: + - ./data:/data + - ./fake.jar:/servers/fake.jar diff --git a/tests/setuponlytests/remove-old-configs/fake.jar b/tests/setuponlytests/remove-old-configs/fake.jar new file mode 100644 index 00000000..e69de29b diff --git a/tests/setuponlytests/remove-old-configs/seed/config/stale.txt b/tests/setuponlytests/remove-old-configs/seed/config/stale.txt new file mode 100644 index 00000000..3367afdb --- /dev/null +++ b/tests/setuponlytests/remove-old-configs/seed/config/stale.txt @@ -0,0 +1 @@ +old diff --git a/tests/setuponlytests/remove-old-configs/verify.sh b/tests/setuponlytests/remove-old-configs/verify.sh new file mode 100644 index 00000000..5be50832 --- /dev/null +++ b/tests/setuponlytests/remove-old-configs/verify.sh @@ -0,0 +1,3 @@ +# verify that the old config was removed and the new one from the pack was installed +mc-image-helper assert fileNotExists config/stale.txt +mc-image-helper assert fileExists config/opt.yml