1- #! /bin/sh
1+ #! /usr/bin/env/sh
2+ # vim:sw=2:ts=2:sts=2:et
23
34set -e
45
56ME=$( 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,8 +18,8 @@ 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"
21+ touch " $conffile " 2> /dev/null || { entrypoint_log " $ME : ERROR : can not modify $conffile (read-only file system?)" ; return 0; }
22+ entrypoint_log " $ME : info: Appending stream block to $conffile to include $stream_output_dir /*.conf"
2223 cat << END >> "$conffile "
2324# added by "$ME " on "$( date) "
2425stream {
@@ -35,21 +36,21 @@ auto_envsubst() {
3536 local stream_suffix=" ${NGINX_ENVSUBST_STREAM_TEMPLATE_SUFFIX:- .stream-template} "
3637 local stream_output_dir=" ${NGINX_ENVSUBST_STREAM_OUTPUT_DIR:-/ etc/ nginx/ stream-conf.d} "
3738 local filter=" ${NGINX_ENVSUBST_FILTER:- } "
38-
3939 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 ) )
40+
41+ defined_envs=$( printf " %s" " $( awk " END { for (name in ENVIRON) { print ( name ~ /${filter} / ) ? name : \"\" } }" < /dev/null ) " )
4142 [ -d " $template_dir " ] || return 0
4243 if [ ! -w " $output_dir " ]; then
4344 entrypoint_log " $ME : ERROR: $template_dir exists, but $output_dir is not writable"
4445 return 0
4546 fi
4647 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 } "
48+ relative_path=" ${template# " $template_dir " / } "
49+ output_path=" $output_dir /${relative_path% " $suffix " } "
4950 subdir=$( dirname " $relative_path " )
5051 # create a subdirectory where the template file exists
5152 mkdir -p " $output_dir /$subdir "
52- entrypoint_log " $ME : Running envsubst on $template to $output_path "
53+ entrypoint_log " $ME : info: Running envsubst on $template to $output_path "
5354 envsubst " $defined_envs " < " $template " > " $output_path "
5455 done
5556
@@ -62,12 +63,12 @@ auto_envsubst() {
6263 fi
6364 add_stream_block
6465 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 } "
66+ relative_path=" ${template# " $template_dir " / } "
67+ output_path=" $stream_output_dir /${relative_path% " $stream_suffix " } "
6768 subdir=$( dirname " $relative_path " )
6869 # create a subdirectory where the template file exists
6970 mkdir -p " $stream_output_dir /$subdir "
70- entrypoint_log " $ME : Running envsubst on $template to $output_path "
71+ entrypoint_log " $ME : info: Running envsubst on $template to $output_path "
7172 envsubst " $defined_envs " < " $template " > " $output_path "
7273 done
7374 fi
0 commit comments