Use -prune for "REPLACE_ENV_VARIABLES_EXCLUDE_PATHS" feature. (#588)

This commit is contained in:
Paul Zühlcke 2020-07-19 01:31:29 +02:00 committed by GitHub
parent 692087dd25
commit 747c188824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 6 deletions

View File

@ -324,7 +324,13 @@ There are some limitations to what characters you can use.
Variables will be replaced in files with the following extensions: Variables will be replaced in files with the following extensions:
`.yml`, `.yaml`, `.txt`, `.cfg`, `.conf`, `.properties`. `.yml`, `.yaml`, `.txt`, `.cfg`, `.conf`, `.properties`.
Specific files can be excluded by listing their name (without path) in the variable `REPLACE_ENV_VARIABLES_EXCLUDES`. Paths can be excluded by listing them in the variable `REPLACE_ENV_VARIABLES_EXCLUDE_PATHS`. Specific files can be excluded by listing their name (without path) in the variable `REPLACE_ENV_VARIABLES_EXCLUDES`.
Paths can be excluded by listing them in the variable `REPLACE_ENV_VARIABLES_EXCLUDE_PATHS`. Path
excludes are recursive. Here is an example:
```
REPLACE_ENV_VARIABLES_EXCLUDE_PATHS="/data/plugins/Essentials/userdata/ /data/plugins/MyPlugin/"
```
Here is a full example where we want to replace values inside a `database.yml`. Here is a full example where we want to replace values inside a `database.yml`.

View File

@ -6,15 +6,20 @@
if isTrue "${REPLACE_ENV_VARIABLES}"; then if isTrue "${REPLACE_ENV_VARIABLES}"; then
log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..." log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..."
findExcludes= findExcludes=
# File excludes
for f in ${REPLACE_ENV_VARIABLES_EXCLUDES}; do for f in ${REPLACE_ENV_VARIABLES_EXCLUDES}; do
findExcludes="${findExcludes} -not -name $f" findExcludes="${findExcludes} -not -name $f"
done done
for p in ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}; do
findExcludes="${findExcludes} -not -path \"*$p*\"" # Directory excludes (recursive)
done dirExcludes=$(join_by " -o -path " ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS})
isDebugging && echo "Using find exclusion: $findExcludes" if [[ $dirExcludes ]]; then
findExcludes+=" -type d ( -path ${dirExcludes} ) -prune"
fi
isDebugging && echo "Using find exclusions: $findExcludes"
while IFS='=' read -r name value ; do while IFS='=' read -r name value ; do
# check if name of env variable matches the prefix # check if name of env variable matches the prefix

View File

@ -1,5 +1,7 @@
#!/bin/bash #!/bin/bash
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
function isURL { function isURL {
local value=$1 local value=$1