1
- #! /bin/sh
1
+ #! /usr/ bin/env sh
2
2
3
3
set -e
4
4
5
- ME=$( basename " $0 " )
5
+ ME=$( basename " ${0} " )
6
6
7
7
entrypoint_log () {
8
8
if [ -z " ${NGINX_ENTRYPOINT_QUIET_LOGS:- } " ]; then
@@ -13,16 +13,16 @@ entrypoint_log() {
13
13
add_stream_block () {
14
14
local conffile=" /etc/nginx/nginx.conf"
15
15
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"
18
18
else
19
19
# 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) "
24
24
stream {
25
- include $stream_output_dir /*.conf;
25
+ include ${ stream_output_dir} /*.conf;
26
26
}
27
27
END
28
28
fi
@@ -38,37 +38,37 @@ auto_envsubst() {
38
38
39
39
local template defined_envs relative_path output_path subdir
40
40
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"
44
44
return 0
45
45
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} " )
50
50
# 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} "
54
54
done
55
55
56
56
# 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"
61
61
return 0
62
62
fi
63
63
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} " )
68
68
# 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} "
72
72
done
73
73
fi
74
74
}
0 commit comments