1- #! /bin/sh
1+ #! /usr/ bin/env sh
22
33set -e
44
5- ME=$( basename " $0 " )
5+ ME=$( basename " ${0} " )
66
77entrypoint_log () {
88 if [ -z " ${NGINX_ENTRYPOINT_QUIET_LOGS:- } " ]; then
@@ -13,16 +13,16 @@ entrypoint_log() {
1313add_stream_block () {
1414 local conffile=" /etc/nginx/nginx.conf"
1515
16- if grep -q -E " \s*stream\s*\{" " $conffile " ; then
17- entrypoint_log " $ME : $conffile contains a stream block; include $stream_output_dir /*.conf to enable stream templates"
16+ if grep -q -E " \s*stream\s*\{" " ${ conffile} " ; then
17+ entrypoint_log " ${ME} : ${ conffile} contains a stream block; include ${ stream_output_dir} /*.conf to enable stream templates"
1818 else
1919 # 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 "
23- # added by "$ME " on "$( date) "
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} "
23+ # added by "${ME} " on "$( date) "
2424stream {
25- include $stream_output_dir /*.conf;
25+ include ${ stream_output_dir} /*.conf;
2626}
2727END
2828 fi
@@ -38,37 +38,37 @@ auto_envsubst() {
3838
3939 local template defined_envs relative_path output_path subdir
4040 defined_envs=$( printf ' ${%s} ' $( awk " END { for (name in ENVIRON) { print ( name ~ /${filter} / ) ? name : \"\" } }" < /dev/null ) )
41- [ -d " $template_dir " ] || return 0
42- if [ ! -w " $output_dir " ]; then
43- entrypoint_log " $ME : ERROR: $template_dir exists, but $output_dir is not writable"
41+ [ -d " ${ template_dir} " ] || return 0
42+ if [ ! -w " ${ output_dir} " ]; then
43+ entrypoint_log " ${ME} : ERROR: ${ template_dir} exists, but ${ output_dir} is not writable"
4444 return 0
4545 fi
46- 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 " } "
49- subdir=$( dirname " $relative_path " )
46+ 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} " } "
49+ subdir=$( dirname " ${ relative_path} " )
5050 # create a subdirectory where the template file exists
51- mkdir -p " $output_dir / $ subdir"
52- entrypoint_log " $ME : Running envsubst on $template to $output_path "
53- envsubst " $defined_envs " < " $template " > " $output_path "
51+ mkdir -p " ${ output_dir} / ${ subdir} "
52+ entrypoint_log " ${ME} : Running envsubst on ${ template} to ${ output_path} "
53+ envsubst " ${ defined_envs} " < " ${ template} " > " ${ output_path} "
5454 done
5555
5656 # Print the first file with the stream suffix, this will be false if there are none
57- if test -n " $( find " $template_dir " -name " *$stream_suffix " -print -quit) " ; then
58- mkdir -p " $stream_output_dir "
59- if [ ! -w " $stream_output_dir " ]; then
60- entrypoint_log " $ME : ERROR: $template_dir exists, but $stream_output_dir is not writable"
57+ if test -n " $( find " ${ template_dir} " -name " *${ stream_suffix} " -print -quit) " ; then
58+ mkdir -p " ${ stream_output_dir} "
59+ if [ ! -w " ${ stream_output_dir} " ]; then
60+ entrypoint_log " ${ME} : ERROR: ${ template_dir} exists, but ${ stream_output_dir} is not writable"
6161 return 0
6262 fi
6363 add_stream_block
64- 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 " } "
67- subdir=$( dirname " $relative_path " )
64+ 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} " } "
67+ subdir=$( dirname " ${ relative_path} " )
6868 # create a subdirectory where the template file exists
69- mkdir -p " $stream_output_dir / $ subdir"
70- entrypoint_log " $ME : Running envsubst on $template to $output_path "
71- envsubst " $defined_envs " < " $template " > " $output_path "
69+ mkdir -p " ${ stream_output_dir} / ${ subdir} "
70+ entrypoint_log " ${ME} : Running envsubst on ${ template} to ${ output_path} "
71+ envsubst " ${ defined_envs} " < " ${ template} " > " ${ output_path} "
7272 done
7373 fi
7474}
0 commit comments