Skip to content

Commit

Permalink
Simplify envvar handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
GrimKriegor committed Jun 25, 2024
1 parent a18bef4 commit 50ac79e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ On startup the container will look for any environment variables prefixed by `TE

Syntax: `TES3MP_SERVER_<section>_<variable>`

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

Expand Down
21 changes: 6 additions & 15 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@

0 comments on commit 50ac79e

Please sign in to comment.