From 50ac79e202d2d2fbb27fdedaabb48c9bff47a14e Mon Sep 17 00:00:00 2001 From: Grim Kriegor Date: Tue, 25 Jun 2024 17:19:17 +0100 Subject: [PATCH] Simplify envvar handling logic --- README.md | 2 +- entrypoint.sh | 21 ++++++--------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 70f9339..d70985d 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ On startup the container will look for any environment variables prefixed by `TE Syntax: `TES3MP_SERVER_
_` -For example `TES3MP_SERVER_GENERAL_MAXIMUM_PLAYERS` correlates to `[General] maximumPlayers` in the configuration file. +For example `TES3MP_SERVER_GENERAL_MAXIMUMPLAYERS` correlates to `[General] maximumPlayers` in the configuration file. ## Getting the image diff --git a/entrypoint.sh b/entrypoint.sh index b4df309..b687c8e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -10,22 +10,13 @@ fi printenv | grep 'TES3MP_SERVER_' | while read -r envvar do - declare -a envvar_exploded=(`echo "$envvar" | sed 's/=/ /g'`) - section_and_variable="${envvar_exploded[0]}" - value="${envvar_exploded[@]: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]}" + envvar_split=$(sed -e "s/TES3MP_SERVER_\([^_]*\)_\([^=]*\)=\(.*\)/\1::\2::\3/" <<< "$envvar") + declare -a envvar_split_array=(`sed 's/::/ /g' <<< "$envvar_split"`) + section="${envvar_split_array[0]}" + variable="${envvar_split_array[1]}" + value="${envvar_split_array[2]}" echo "Applying \"[$section] $variable = $value\" to the configuration" - sed -i \ - "/\[$section\]/I,/\[/ s/\($variable =\).*$/\1 $value/" \ - ./tes3mp-server-default.cfg + sed -i "/\[$section\]/I,/\[/ s/\($variable =\).*$/\1 $value/I" ./tes3mp-server-default.cfg done ./tes3mp-server $@