Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DLC_SPACE_AGE environment variable #519

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,19 @@ The `server-settings.json` file may then contain the variable references like th

These are the environment variables which can be specified at container run time.

| Variable Name | Description | Default | Available in |
| - | - | - | - |
| GENERATE_NEW_SAVE | Generate a new save if one does not exist before starting the server | false | 0.17+ |
| LOAD_LATEST_SAVE | Load latest when true. Otherwise load SAVE_NAME | true | 0.17+ |
| PORT | UDP port the server listens on | 34197 | 0.15+ |
| BIND | IP address (v4 or v6) the server listens on (IP\[:PORT]) | | 0.15+ |
| RCON_PORT | TCP port the rcon server listens on | 27015 | 0.15+ |
| SAVE_NAME | Name to use for the save file | _autosave1 | 0.17+ |
| TOKEN | factorio.com token | | 0.17+ |
| UPDATE_MODS_ON_START | If mods should be updated before starting the server | | 0.17+ |
| USERNAME | factorio.com username | | 0.17+ | |
| CONSOLE_LOG_LOCATION | Saves the console log to the specifies location | |
| Variable Name | Description | Default | Available in |
|----------------------|----------------------------------------------------------------------|------------|--------------|
| GENERATE_NEW_SAVE | Generate a new save if one does not exist before starting the server | false | 0.17+ |
| LOAD_LATEST_SAVE | Load latest when true. Otherwise load SAVE_NAME | true | 0.17+ |
| PORT | UDP port the server listens on | 34197 | 0.15+ |
| BIND | IP address (v4 or v6) the server listens on (IP\[:PORT]) | | 0.15+ |
| RCON_PORT | TCP port the rcon server listens on | 27015 | 0.15+ |
| SAVE_NAME | Name to use for the save file | _autosave1 | 0.17+ |
| TOKEN | factorio.com token | | 0.17+ |
| UPDATE_MODS_ON_START | If mods should be updated before starting the server | | 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 | true | 2.0.8+ |

**Note:** All environment variables are compared as strings

Expand Down
38 changes: 38 additions & 0 deletions docker/files/docker-dlc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -eou pipefail

# Path to the mod-list.json file
MOD_LIST_FILE="$MODS/mod-list.json"

enable_mod()
{
echo "Enable mod $1 for DLC"
jq --arg mod_name "$1" 'if .mods | map(.name) | index($mod_name) then .mods |= map(if .name == $mod_name and .enabled == false then .enabled = true else . end) else . end' "$MOD_LIST_FILE" > "$MOD_LIST_FILE.tmp"
mv "$MOD_LIST_FILE.tmp" "$MOD_LIST_FILE"
}

disable_mod()
{
echo "Disable mod $1 for DLC"
jq --arg mod_name "$1" 'if .mods | map(.name) | index($mod_name) then .mods |= map(if .name == $mod_name and .enabled == true then .enabled = false else . end) else .mods += [{"name": $mod_name, "enabled": false}] end' "$MOD_LIST_FILE" > "$MOD_LIST_FILE.tmp"
mv "$MOD_LIST_FILE.tmp" "$MOD_LIST_FILE"
}

# Enable or disable DLCs if configured
if [[ ${DLC_SPACE_AGE:-} == "true" ]]; then
# Define the DLC mods
DLC_MODS=("elevated-rails" "quality" "space-age")

# Iterate over each DLC mod
for MOD in "${DLC_MODS[@]}"; do
enable_mod "$MOD"
done
else
# Define the DLC mods
DLC_MODS=("elevated-rails" "quality" "space-age")

# Iterate over each DLC mod
for MOD in "${DLC_MODS[@]}"; do
disable_mod "$MOD"
done
fi
2 changes: 2 additions & 0 deletions docker/files/docker-entrypoint.sh

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[shellcheck] reported by reviewdog 🐶
Use -n instead of ! -z. SC2236

if [[ ! -z "$PRESET" ]]; then

Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ if [[ ${UPDATE_MODS_ON_START:-} == "true" ]]; then
./docker-update-mods.sh
fi

./docker-dlc.sh

EXEC=""
if [[ $(id -u) = 0 ]]; then
# Update the User and Group ID based on the PUID/PGID variables
Expand Down