forked from itzg/docker-minecraft-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-finalSetupEnvVariables
51 lines (40 loc) · 1.44 KB
/
start-finalSetupEnvVariables
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
. ${SCRIPTS:-/}start-utils
: ${ENV_VARIABLE_PREFIX:=CFG_}
if isTrue "${REPLACE_ENV_VARIABLES}"; then
log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX ..."
# File excludes
fileExcludes=
for f in ${REPLACE_ENV_VARIABLES_EXCLUDES}; do
fileExcludes="${fileExcludes} -not -name $f"
done
# Directory excludes (recursive)
dirExcludes=$(join_by " -o -path " ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS})
if [[ $dirExcludes ]]; then
dirExcludes=" -type d ( -path ${dirExcludes} ) -prune -o"
fi
isDebugging && echo "Using find file exclusions: $fileExcludes"
isDebugging && echo "Using find directory exclusions: $dirExcludes"
for name in $(compgen -v $ENV_VARIABLE_PREFIX); do
# check if name of env variable matches the prefix
# sanity check environment variables to avoid code injections
# Read content from file environment
if [[ $name = *"_FILE" ]]; then
value=$(<${!name})
name="${name%_FILE}"
else
value=${!name}
fi
log "Replacing $name with $value ..."
value=${value//\\/\\\\}
value=${value//#/\\#}
find /data/ \
$dirExcludes \
-type f \
\( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" \
-or -name "*.conf" -or -name "*.properties" \) \
$fileExcludes \
-exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \;
done
fi
exec ${SCRIPTS:-/}start-minecraftFinalSetup $@