11#! /bin/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,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,7 +41,8 @@ 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" 
@@ -49,8 +54,8 @@ auto_envsubst() {
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
@@ -67,8 +72,8 @@ auto_envsubst() {
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