File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
set -eu
3
3
4
+ # usage: file_env VAR [DEFAULT]
5
+ # ie: file_env 'XYZ_DB_PASSWORD' 'example'
6
+ # (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
7
+ # "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
8
+ file_env () {
9
+ local var=" $1 "
10
+ local fileVar=" ${var} _FILE"
11
+ local def=" ${2:- } "
12
+ if [ " ${! var:- } " ] && [ " ${! fileVar:- } " ]; then
13
+ echo >&2 " error: both $var and $fileVar are set (but are exclusive)"
14
+ exit 1
15
+ fi
16
+ local val=" $def "
17
+ if [ " ${! var:- } " ]; then
18
+ val=" ${! var} "
19
+ elif [ " ${! fileVar:- } " ]; then
20
+ val=" $( < " ${! fileVar} " ) "
21
+ fi
22
+ export " $var " =" $val "
23
+ unset " $fileVar "
24
+ }
25
+
26
+ file_env ' RABBITMQ_DEFAULT_PASS'
27
+
4
28
# allow the container to be started with `--user`
5
29
if [[ " $1 " == rabbitmq* ]] && [ " $( id -u) " = ' 0' ]; then
6
30
if [ " $1 " = ' rabbitmq-server' ]; then
Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
set -eu
3
3
4
+ # usage: file_env VAR [DEFAULT]
5
+ # ie: file_env 'XYZ_DB_PASSWORD' 'example'
6
+ # (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
7
+ # "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
8
+ file_env () {
9
+ local var=" $1 "
10
+ local fileVar=" ${var} _FILE"
11
+ local def=" ${2:- } "
12
+ if [ " ${! var:- } " ] && [ " ${! fileVar:- } " ]; then
13
+ echo >&2 " error: both $var and $fileVar are set (but are exclusive)"
14
+ exit 1
15
+ fi
16
+ local val=" $def "
17
+ if [ " ${! var:- } " ]; then
18
+ val=" ${! var} "
19
+ elif [ " ${! fileVar:- } " ]; then
20
+ val=" $( < " ${! fileVar} " ) "
21
+ fi
22
+ export " $var " =" $val "
23
+ unset " $fileVar "
24
+ }
25
+
26
+ file_env ' RABBITMQ_DEFAULT_PASS'
27
+
4
28
# allow the container to be started with `--user`
5
29
if [[ " $1 " == rabbitmq* ]] && [ " $( id -u) " = ' 0' ]; then
6
30
if [ " $1 " = ' rabbitmq-server' ]; then
You can’t perform that action at this time.
0 commit comments