This repository was archived by the owner on Jul 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenv_var_script.sh
More file actions
executable file
·145 lines (121 loc) · 4.54 KB
/
env_var_script.sh
File metadata and controls
executable file
·145 lines (121 loc) · 4.54 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
remplace_in_file() {
chmod a+w $1
sed -i "s|\${root_url}|$KHEOPS_ROOT_URL|" $1
sed -i "s|\${DICOMWebProxy_url}|$KHEOPS_DICOMWEB_PROXY_HOST:$KHEOPS_DICOMWEB_PROXY_PORT|" $1
sed -i "s|\${kheopsAuthorization_url}|http://$KHEOPS_AUTHORIZATION_HOST:$KHEOPS_AUTHORIZATION_PORT|" $1
sed -i "s|\${kheopsAuthorizationProxy_url}|http://$KHEOPS_PACS_PEP_HOST:$KHEOPS_PACS_PEP_PORT|" $1
sed -i "s|\${kheopsZipper_url}|http://$KHEOPS_ZIPPER_HOST:$KHEOPS_ZIPPER_PORT|" $1
sed -i "s|\${kheopsWebUI_url}|http://$KHEOPS_UI_HOST:$KHEOPS_UI_PORT|" $1
sed -i "s|\${server_name}|$roothost|" $1
sed -i "s|\${keycloak_url}|$proto$hostport|g" $1
}
missing_env_var_secret=false
#Verify environment variables
if [[ -z $KHEOPS_ROOT_URL ]]; then
echo "Missing KHEOPS_ROOT_URL environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_ROOT_URL \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_DICOMWEB_PROXY_HOST ]]; then
echo "Missing KHEOPS_DICOMWEB_PROXY_HOST environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_DICOMWEB_PROXY_HOST \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_DICOMWEB_PROXY_PORT ]]; then
echo "Missing KHEOPS_DICOMWEB_PROXY_PORT environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_DICOMWEB_PROXY_PORT \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_AUTHORIZATION_HOST ]]; then
echo "Missing KHEOPS_AUTHORIZATION_HOST environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_AUTHORIZATION_HOST \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_AUTHORIZATION_PORT ]]; then
echo "Missing KHEOPS_AUTHORIZATION_PORT environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_AUTHORIZATION_PORT \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_PACS_PEP_HOST ]]; then
echo "Missing KHEOPS_PACS_PEP_HOST environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_PACS_PEP_HOST \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_PACS_PEP_PORT ]]; then
echo "Missing KHEOPS_PACS_PEP_PORT environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_PACS_PEP_PORT \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_ZIPPER_HOST ]]; then
echo "Missing KHEOPS_ZIPPER_HOST environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_ZIPPER_HOST \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_ZIPPER_PORT ]]; then
echo "Missing KHEOPS_ZIPPER_PORT environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_ZIPPER_PORT \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_UI_HOST ]]; then
echo "Missing KHEOPS_UI_HOST environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_UI_HOST \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_UI_PORT ]]; then
echo "Missing KHEOPS_UI_PORT environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_UI_PORT \e[92mOK\e[0m"
fi
if [[ -z $KHEOPS_OIDC_PROVIDER ]]; then
echo "Missing KHEOPS_OIDC_PROVIDER environment variable"
missing_env_var_secret=true
else
echo -e "environment variable KHEOPS_OIDC_PROVIDER \e[92mOK\e[0m"
fi
#if missing env var or secret => exit
if [[ $missing_env_var_secret = true ]]; then
exit 1
else
echo -e "all nginx secrets and all env var \e[92mOK\e[0m"
fi
# extract the protocol
proto="$(echo $KHEOPS_OIDC_PROVIDER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
# remove the protocol
url="$(echo ${KHEOPS_OIDC_PROVIDER/$proto/})"
# extract the user (if any)
user="$(echo $url | grep @ | cut -d@ -f1)"
# extract the host and port
hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
# by request host without port
host="$(echo $hostport | sed -e 's,:.*,,g')"
# by request - try to extract the port
port="$(echo $hostport | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"
# extract the path (if any)
path="$(echo $url | grep / | cut -d/ -f2-)"
export roothost="$(awk -F/ '{sub("^[^@]+@","",$3); print $3}' <<<$KHEOPS_ROOT_URL)"
if /usr/bin/find "/etc/nginx/kheops/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
echo >&3 "$0: /etc/nginx/kheops/ is not empty, will attempt to perform configuration"
echo >&3 "$0: Looking for .conf file in /etc/nginx/kheops/"
find "/etc/nginx/kheops/" -follow -type f -print | sort -n | while read -r f; do
case "$f" in
*.conf)
remplace_in_file ${f}
;;
*) echo >&3 "$0: Ignoring $f";;
esac
done
fi
remplace_in_file /etc/nginx/conf.d/kheops.conf
echo "Ending setup NGINX env var"