11#! /bin/sh
2+ # vim:sw=2:ts=2:sts=2:et
23
34set -e
45
5- ME=$( basename $0 )
6+ ME=$( basename " $0 " )
67
78entrypoint_log () {
8- if [ -z " ${NGINX_ENTRYPOINT_QUIET_LOGS:- } " ]; then
9- echo " $@ "
10- fi
9+ if [ -z " ${NGINX_ENTRYPOINT_QUIET_LOGS:- } " ]; then
10+ echo " $@ "
11+ fi
1112}
1213
1314add_stream_block () {
@@ -17,9 +18,12 @@ add_stream_block() {
1718 entrypoint_log " $ME : $conffile contains a stream block; include $stream_output_dir /*.conf to enable stream templates"
1819 else
1920 # check if the file can be modified, e.g. not on a r/o filesystem
20- touch " $conffile " 2> /dev/null || { entrypoint_log " $ME : info: can not modify $conffile (read-only file system?)" ; exit 0; }
21- entrypoint_log " $ME : Appending stream block to $conffile to include $stream_output_dir /*.conf"
22- cat << END >> "$conffile "
21+ touch " $conffile " 2> /dev/null || {
22+ entrypoint_log " $ME : ERROR: can not modify $conffile (read-only file system?)"
23+ exit 0
24+ }
25+ entrypoint_log " $ME : info: Appending stream block to $conffile to include $stream_output_dir /*.conf"
26+ cat << END >>"$conffile "
2327# added by "$ME " on "$( date) "
2428stream {
2529 include $stream_output_dir /*.conf;
@@ -37,20 +41,21 @@ auto_envsubst() {
3741 local filter=" ${NGINX_ENVSUBST_FILTER:- } "
3842
3943 local template defined_envs relative_path output_path subdir
40- defined_envs=$( printf ' ${%s} ' $( awk " END { for (name in ENVIRON) { print ( name ~ /${filter} / ) ? name : \"\" } }" < /dev/null ) )
44+
45+ defined_envs=$( printf ' ${%s} ' $( awk " END { for (name in ENVIRON) { print ( name ~ /${filter} / ) ? name : \"\" } }" < /dev/null) )
4146 [ -d " $template_dir " ] || return 0
4247 if [ ! -w " $output_dir " ]; then
4348 entrypoint_log " $ME : ERROR: $template_dir exists, but $output_dir is not writable"
4449 return 0
4550 fi
4651 find " $template_dir " -follow -type f -name " *$suffix " -print | while read -r template; do
47- relative_path=" ${template# $template_dir / } "
48- output_path=" $output_dir /${relative_path% $suffix } "
52+ relative_path=" ${template# " $template_dir /" } "
53+ output_path=" $output_dir /${relative_path% " $suffix " } "
4954 subdir=$( dirname " $relative_path " )
5055 # create a subdirectory where the template file exists
5156 mkdir -p " $output_dir /$subdir "
52- entrypoint_log " $ME : Running envsubst on $template to $output_path "
53- envsubst " $defined_envs " < " $template " > " $output_path "
57+ entrypoint_log " $ME : info: Running envsubst on $template to $output_path "
58+ envsubst " $defined_envs " < " $template " > " $output_path "
5459 done
5560
5661 # Print the first file with the stream suffix, this will be false if there are none
@@ -62,13 +67,13 @@ auto_envsubst() {
6267 fi
6368 add_stream_block
6469 find " $template_dir " -follow -type f -name " *$stream_suffix " -print | while read -r template; do
65- relative_path=" ${template# $template_dir / } "
66- output_path=" $stream_output_dir /${relative_path% $stream_suffix } "
70+ relative_path=" ${template# " $template_dir /" } "
71+ output_path=" $stream_output_dir /${relative_path% " $stream_suffix " } "
6772 subdir=$( dirname " $relative_path " )
6873 # create a subdirectory where the template file exists
6974 mkdir -p " $stream_output_dir /$subdir "
70- entrypoint_log " $ME : Running envsubst on $template to $output_path "
71- envsubst " $defined_envs " < " $template " > " $output_path "
75+ entrypoint_log " $ME : info: Running envsubst on $template to $output_path "
76+ envsubst " $defined_envs " < " $template " > " $output_path "
7277 done
7378 fi
7479}
0 commit comments