Skip to content

Commit 50ac79e

Browse files
committed
Simplify envvar handling logic
1 parent a18bef4 commit 50ac79e

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ On startup the container will look for any environment variables prefixed by `TE
1616

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

19-
For example `TES3MP_SERVER_GENERAL_MAXIMUM_PLAYERS` correlates to `[General] maximumPlayers` in the configuration file.
19+
For example `TES3MP_SERVER_GENERAL_MAXIMUMPLAYERS` correlates to `[General] maximumPlayers` in the configuration file.
2020

2121
## Getting the image
2222

entrypoint.sh

+6-15
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,13 @@ fi
1010

1111
printenv | grep 'TES3MP_SERVER_' | while read -r envvar
1212
do
13-
declare -a envvar_exploded=(`echo "$envvar" | sed 's/=/ /g'`)
14-
section_and_variable="${envvar_exploded[0]}"
15-
value="${envvar_exploded[@]:1}"
16-
section_and_variable=$(echo "$section_and_variable" \
17-
| sed -e 's/TES3MP_SERVER_\([^_]*\)_\(.*\)/\1:\2/' \
18-
| tr '[:upper:]' '[:lower:]' \
19-
| awk -F "_" \
20-
'{printf "%s", $1; \
21-
for(i=2; i<=NF; i++) printf "%s", toupper(substr($i,1,1)) substr($i,2); print"";}')
22-
declare -a section_and_variable_exploded=(`echo "$section_and_variable" | sed 's/:/ /g'`)
23-
section="${section_and_variable_exploded[0]}"
24-
variable="${section_and_variable_exploded[1]}"
13+
envvar_split=$(sed -e "s/TES3MP_SERVER_\([^_]*\)_\([^=]*\)=\(.*\)/\1::\2::\3/" <<< "$envvar")
14+
declare -a envvar_split_array=(`sed 's/::/ /g' <<< "$envvar_split"`)
15+
section="${envvar_split_array[0]}"
16+
variable="${envvar_split_array[1]}"
17+
value="${envvar_split_array[2]}"
2518
echo "Applying \"[$section] $variable = $value\" to the configuration"
26-
sed -i \
27-
"/\[$section\]/I,/\[/ s/\($variable =\).*$/\1 $value/" \
28-
./tes3mp-server-default.cfg
19+
sed -i "/\[$section\]/I,/\[/ s/\($variable =\).*$/\1 $value/I" ./tes3mp-server-default.cfg
2920
done
3021

3122
./tes3mp-server $@

0 commit comments

Comments
 (0)