Skip to content

Commit

Permalink
Make the ini patching process section aware
Browse files Browse the repository at this point in the history
  • Loading branch information
GrimKriegor committed Jun 24, 2024
1 parent c94f7af commit a18bef4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ Values can be passed into the server configuration file via environment variable

On startup the container will look for any environment variables prefixed by `TES3MP_SERVER_` and attempt to update them on `tes3mp-server-default.cfg`.

Environment variables should be represented as uppercase snake case.
Syntax: `TES3MP_SERVER_<section>_<variable>`

For example `TES3MP_SERVER_MAXIMUM_PLAYERS` correlates to `maximumPlayers` in the configuration file.
For example `TES3MP_SERVER_GENERAL_MAXIMUM_PLAYERS` correlates to `[General] maximumPlayers` in the configuration file.

## Getting the image

Expand Down Expand Up @@ -54,7 +54,7 @@ Replace the path described at the `-v` (volume) argument to a directory on your
```bash
docker run -it \
--name TES3MP-server \
-e TES3MP_SERVER_HOSTNAME="Containerized TES3MP Server" \
-e TES3MP_SERVER_GENERAL_HOSTNAME="Containerized TES3MP Server" \
-v "$HOME/TES3MP/data:/server/data" \
-p "25565:25565/udp" \
tes3mp/server
Expand All @@ -65,7 +65,7 @@ docker run -it \
```bash
docker run -it \
--name TES3MP-server \
-e TES3MP_SERVER_HOSTNAME="Containerized TES3MP Server" \
-e TES3MP_SERVER_GENERAL_HOSTNAME="Containerized TES3MP Server" \
-v "$HOME/TES3MP/data:/server/data" \
-p "25565:25565/udp" \
tes3mp/server:0.6.3
Expand Down Expand Up @@ -93,7 +93,7 @@ services:
server:
image: "tes3mp/server:0.6.3"
environment:
- TES3MP_SERVER_HOSTNAME="Containerized TES3MP Server"
- TES3MP_SERVER_GENERAL_HOSTNAME="Containerized TES3MP Server"
volumes:
- "./data:/server/data"
ports:
Expand All @@ -102,7 +102,7 @@ services:
server-legacy:
image: "tes3mp/server:0.5.2"
environment:
- TES3MP_SERVER_HOSTNAME="Containerized TES3MP Server (Legacy)"
- TES3MP_SERVER_GENERAL_HOSTNAME="Containerized TES3MP Server (Legacy)"
volumes:
- "./data-legacy:/server/data"
ports:
Expand Down
15 changes: 9 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ fi

printenv | grep 'TES3MP_SERVER_' | while read -r envvar
do
declare -a envvar_exploded=(`echo "$envvar" |sed 's/=/ /g'`)
variable="${envvar_exploded[0]}"
declare -a envvar_exploded=(`echo "$envvar" | sed 's/=/ /g'`)
section_and_variable="${envvar_exploded[0]}"
value="${envvar_exploded[@]:1}"
echo "Applying value of \"$variable\" to the configuration"
variable=$(echo "$variable" \
| sed -e 's/TES3MP_SERVER_\(.*\)/\1/' \
section_and_variable=$(echo "$section_and_variable" \
| sed -e 's/TES3MP_SERVER_\([^_]*\)_\(.*\)/\1:\2/' \
| tr '[:upper:]' '[:lower:]' \
| awk -F "_" \
'{printf "%s", $1; \
for(i=2; i<=NF; i++) printf "%s", toupper(substr($i,1,1)) substr($i,2); print"";}')
declare -a section_and_variable_exploded=(`echo "$section_and_variable" | sed 's/:/ /g'`)
section="${section_and_variable_exploded[0]}"
variable="${section_and_variable_exploded[1]}"
echo "Applying \"[$section] $variable = $value\" to the configuration"
sed -i \
"s/^\($variable =\).*$/\1 $value/" \
"/\[$section\]/I,/\[/ s/\($variable =\).*$/\1 $value/" \
./tes3mp-server-default.cfg
done

Expand Down

0 comments on commit a18bef4

Please sign in to comment.