forked from chainstacklabs/eth-proxy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
49 lines (44 loc) · 1.86 KB
/
entrypoint.sh
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
#!/bin/bash
set -eu
export DNS="${DNS}"
export PORT="${RPC_PORT:-80}"
export WS="${WS:-"NO"}"
export STATUS_METHOD="${STATUS_METHOD:-net_version}"
export AUTHORIZATION_HEADER="${AUTHORIZATION_HEADER:-}"
if [[ ! -z "${WS_ENDPOINT:-}" ]]; then
export WS="YES"
fi
if [[ ! -z "${ENDPOINT:-}" ]]; then
export RPC_ENDPOINT="${ENDPOINT}"
export WS_ENDPOINT="${ENDPOINT}"
else
export RPC_ENDPOINT="${RPC_ENDPOINT}"
export WS_ENDPOINT="${WS_ENDPOINT}"
fi
if [[ -z "${USERNAME:-}" || -z "${PASSWORD:-}" ]] && [[ "$WS" = "YES" ]]; then
# WS and no auth
file=/tmp/rpc.ws.conf.template
#envsubst '${AUTHORIZATION_HEADER}' < /tmp/rpc.ws.conf.template > /etc/nginx/conf.d/default.conf
elif [[ -z "${USERNAME:-}" || -z "${PASSWORD:-}" ]]; then
# no ws and no auth
file=/tmp/rpc.conf.template
#envsubst '${AUTHORIZATION_HEADER}' < /tmp/rpc.conf.template > /etc/nginx/conf.d/default.conf
else
AUTHORIZATION=$(echo -n "${USERNAME}:${PASSWORD}" | base64 | tr -d \\n)
AUTHORIZATION_HEADER=$(echo -n "proxy_set_header Authorization \"Basic ${AUTHORIZATION}\";")
if [[ "$WS" = "YES" ]]; then
# ws and auth
file=/tmp/rpc.ws.conf.template
#envsubst '${AUTHORIZATION_HEADER}' < /tmp/rpc.ws.conf.template > /etc/nginx/conf.d/default.conf
else
# no ws and auth
file=/tmp/rpc.conf.template
#envsubst '${AUTHORIZATION_HEADER}' < /tmp/rpc.conf.template > /etc/nginx/conf.d/default.conf
fi
fi
envsubst '${AUTHORIZATION_HEADER}' < $file > /etc/nginx/conf.d/default.conf
envsubst '${DNS} ${PORT}' < /tmp/common.template > /etc/nginx/conf.d/common.template
envsubst '${STATUS_METHOD}' < /tmp/status.template > /etc/nginx/conf.d/status.template
envsubst '${RPC_ENDPOINT}' < /tmp/rpc.template > /etc/nginx/conf.d/rpc.template
envsubst '${WS_ENDPOINT}' < /tmp/ws.template > /etc/nginx/conf.d/ws.template
exec "$@"