From bd9914a1fd1aded2e176f4deedb610f2f522ab1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chrislieb=C3=A4r?= Date: Sat, 27 Sep 2025 17:35:39 +0200 Subject: [PATCH] Add option to ignore mods from auto-update --- README.md | 3 +++ docker-compose.yml | 2 ++ docker/docker-compose.yml | 1 + docker/files/docker-update-mods.sh | 2 +- docker/files/update-mods.sh | 29 ++++++++++++++++++++++++++++- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2ef76410..728d1da2 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,8 @@ Copy mods into the mods folder and restart the server. As of 0.17 a new environment variable was added ``UPDATE_MODS_ON_START`` which if set to ``true`` will cause the mods get to updated on server start. If set a valid [Factorio Username and Token](https://www.factorio.com/profile) must be supplied or else the server will not start. They can either be set as docker secrets, environment variables, or pulled from the server-settings.json file. +To prevent specific mods from being automatically updated, you can use the ``UPDATE_IGNORE`` environment variable with a comma-separated list of mod names. For example: ``UPDATE_IGNORE=mod1,mod2,mod3`` will skip updates for those three mods. This can be useful to prevent compatibility issues when certain mods should remain at specific versions. Be warned that it can also create compatibility issues. + **Note:** When using the Space Age DLC, the built-in mods (`elevated-rails`, `quality`, and `space-age`) are automatically skipped during mod updates to prevent conflicts. These mods are included with the DLC and should not be downloaded separately. ### Scenarios @@ -292,6 +294,7 @@ These are the environment variables which can be specified at container run time | PRESET | Map generation preset when GENERATE_NEW_SAVE is true | | 0.17+ | | TOKEN | factorio.com token | | 0.17+ | | UPDATE_MODS_ON_START | If mods should be updated before starting the server | | 0.17+ | +| UPDATE_IGNORE | Comma-separated list of mod names to skip during automatic updates | | 0.17+ | | USERNAME | factorio.com username | | 0.17+ | | CONSOLE_LOG_LOCATION | Saves the console log to the specifies location | | | | DLC_SPACE_AGE | Enables or disables the mods for DLC Space Age in mod-list.json[^1] | true | 2.0.8+ | diff --git a/docker-compose.yml b/docker-compose.yml index db2fe5b2..b18d1187 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,8 @@ services: - ./data:/factorio environment: - UPDATE_MODS_ON_START=true + # Uncomment to skip updating specific mods + # - UPDATE_IGNORE=mod1,mod2,mod3 # Uncomment to enable autoupdate via watchtower #labels: diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index af768d67..ddd51a15 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -17,6 +17,7 @@ services: # - PUID=1000 # - PGID=1000 # - UPDATE_MODS_ON_START=true + # - UPDATE_IGNORE=mod1,mod2,mod3 # - USERNAME=FactorioUsername # - TOKEN=FactorioToken # - PORT=34198 diff --git a/docker/files/docker-update-mods.sh b/docker/files/docker-update-mods.sh index bd3a223b..47dac482 100755 --- a/docker/files/docker-update-mods.sh +++ b/docker/files/docker-update-mods.sh @@ -25,4 +25,4 @@ if [[ -z ${TOKEN:-} ]]; then echo "You need to provide your Factorio token to update mods." fi -./update-mods.sh "$VERSION" "$MODS" "$USERNAME" "$TOKEN" +./update-mods.sh "$VERSION" "$MODS" "$USERNAME" "$TOKEN" "${UPDATE_IGNORE:-}" diff --git a/docker/files/update-mods.sh b/docker/files/update-mods.sh index 6c58ff55..7653b00c 100755 --- a/docker/files/update-mods.sh +++ b/docker/files/update-mods.sh @@ -5,6 +5,7 @@ FACTORIO_VERSION=$1 MOD_DIR=$2 USERNAME=$3 TOKEN=$4 +UPDATE_IGNORE=$5 MOD_BASE_URL="https://mods.factorio.com" @@ -158,6 +159,28 @@ get_mod_info() done < <(echo "$mod_info_json" | jq -c ".releases|sort_by(.released_at)|reverse|.[]") } +# Check if a mod should be ignored based on UPDATE_IGNORE environment variable +is_mod_ignored() { + local mod_name="$1" + + # If UPDATE_IGNORE is not set or empty, don't ignore any mods + if [[ -z "${UPDATE_IGNORE:-}" ]]; then + return 1 + fi + + # Split the comma-separated list and check if mod_name is in it + IFS=',' read -ra ignored_mods <<< "$UPDATE_IGNORE" + for ignored_mod in "${ignored_mods[@]}"; do + # Trim whitespace from ignored_mod + ignored_mod=$(echo "$ignored_mod" | xargs) + if [[ "$mod_name" == "$ignored_mod" ]]; then + return 0 + fi + done + + return 1 +} + update_mod() { MOD_NAME="$1" @@ -233,7 +256,11 @@ if [[ -f $MOD_DIR/mod-list.json ]]; then jq -r ".mods|map(select(.enabled))|.[].name" "$MOD_DIR/mod-list.json" | while read -r mod; do # Skip base mod and DLC built-in mods if [[ $mod != base ]] && [[ $mod != elevated-rails ]] && [[ $mod != quality ]] && [[ $mod != space-age ]]; then - update_mod "$mod" || true + if is_mod_ignored "$mod"; then + print_success "Skipping mod $mod (listed in UPDATE_IGNORE)" + else + update_mod "$mod" || true + fi fi done fi