From 22749e08b79ba65628cc2ad9cd3808d6c8fdd8e0 Mon Sep 17 00:00:00 2001 From: alberto-is <146236252+alberto-is@users.noreply.github.com> Date: Thu, 17 Sep 2026 14:25:14 +0200 Subject: [PATCH] Add REMOVE_OLD_CONFIGS to clear old configs before modpack install (#4266) --- docs/mods-and-plugins/index.md | 2 + scripts/start-setupModpack | 9 ++++ scripts/start-utils | 17 +++++++ .../remove-old-configs/configs.zip | Bin 0 -> 324 bytes .../remove-old-configs/docker-compose.yml | 43 ++++++++++++++++++ .../remove-old-configs/fake.jar | 0 .../remove-old-configs/seed/config/stale.txt | 1 + .../remove-old-configs/verify.sh | 3 ++ 8 files changed, 75 insertions(+) create mode 100644 tests/setuponlytests/remove-old-configs/configs.zip create mode 100644 tests/setuponlytests/remove-old-configs/docker-compose.yml create mode 100644 tests/setuponlytests/remove-old-configs/fake.jar create mode 100644 tests/setuponlytests/remove-old-configs/seed/config/stale.txt create mode 100644 tests/setuponlytests/remove-old-configs/verify.sh 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 0000000000000000000000000000000000000000..5e30e0a42143923a0d7640ed77ffce62f84c8374 GIT binary patch literal 324 zcmWIWW@h1H00Cbf