-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathload-config.sh
More file actions
executable file
·45 lines (40 loc) · 1.53 KB
/
load-config.sh
File metadata and controls
executable file
·45 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# Source: http://stackoverflow.com/a/246128
# This was accurate more than DIR_NAME=$(dirname $(readlink -f "$0"))
DIR_NAME="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd ${DIR_NAME}
export PREFIX_COLOR_SUCCESS="\e[38;5;82m# "
export PREFIX_COLOR_WARNING="\e[38;5;202m"
export PREFIX_COLOR_ERROR="\e[31m"
export SUFFIX_COLOR_DEFAULT="\e[39m"
function exit_on_missing_config(){
if [ ! -f "config.json" ]; then
echo -e "${PREFIX_COLOR_ERROR}Please make sure to create config.json file and to configure it before creating any container that is using the proxy web server${SUFFIX_COLOR_DEFAULT}"
echo -e "${PREFIX_COLOR_ERROR}cp config.json.example config.json${SUFFIX_COLOR_DEFAULT}"
exit 1
fi
}
function parse_config(){
default="$1"
shift;
params="$@"
attrs=""
for i in ${params}; do
attrs="${attrs}[${i}]"
done
echo -n $(cat config.json 2> /dev/null | python3 -c "import json,sys;print(json.load(sys.stdin)${attrs})" 2> /dev/null || echo $default)
}
function parse_config_n(){
default="$1"
shift;
params="$@"
attrs=""
for i in ${params}; do
attrs="${attrs}[${i}]"
done
echo -n $(cat config.json 2> /dev/null | python3 -c "import json,sys;print(len(json.load(sys.stdin)${attrs}))" 2> /dev/null || echo $default)
}
export N_PROJECTS=$(parse_config_n '0' "'projects'")
export N_TLS=$(parse_config_n '0' "'tls'")
export COMMON_TASKS_COMPATIBLE=$(parse_config '' "'common'" "'tasks_compatible'")
export COMMON_PROXY_CONF_PATH=$(parse_config '' "'common'" "'proxy_conf_path'")