Skip to content

Commit 773f78c

Browse files
committed
only replace files with matches in the same directory
1 parent 5b9e37a commit 773f78c

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed
Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

3-
# A stripped down copy paste of https://github.com/nginxinc/docker-nginx/blob/master/entrypoint/20-envsubst-on-templates.sh
3+
# A stripped down copy of https://github.com/nginxinc/docker-nginx/blob/master/entrypoint/20-envsubst-on-templates.sh
44

55
set -e
66

7-
ME=$(basename $0)
7+
ME=$(basename "$0")
88

99
www_envsubst() {
1010
local www_dir="${NGINX_ENVSUBST_WWW_DIR:-/var/www/}"
11-
local template defined_envs
1211

13-
defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))
14-
1512
[ -d "$www_dir" ] || return 0
1613
if [ ! -w "$www_dir" ]; then
1714
echo >&3 "$ME: ERROR: $www_dir is not writable"
1815
return 0
1916
fi
2017

21-
find "$www_dir" -follow -type f -print | while read -r file; do
22-
tmpfile=$(mktemp)
23-
cp --attributes-only --preserve "$file" "$tmpfile"
24-
envsubst "$defined_envs" < "$file" > "$tmpfile" && mv "$tmpfile" "$file"
18+
grep --recursive --no-messages --files-with-matches "\${" "$www_dir" | while read -r file; do
19+
envsubst < "$file" > "$file.new" && cp --attributes-only --preserve "$file" "$file.new" && mv "$file.new" "$file"
2520
done
2621
}
2722

2823
www_envsubst
2924

30-
exit 0
25+
exit 0

0 commit comments

Comments
 (0)