-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·140 lines (131 loc) · 3.66 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
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
#!/bin/sh
set -e
CBWXPROXY_BEDROCK_ENABLE=${CBWXPROXY_BEDROCK_ENABLE:-"false"}
CBWXPROXY_BEDROCK_PORT=${CBWXPROXY_BEDROCK_PORT:-"19132"}
CBWXPROXY_BEDROCK_REMOTE_HOST=${CBWXPROXY_BEDROCK_REMOTE_HOST:-""}
CBWXPROXY_JAVA_ENABLE=${CBWXPROXY_JAVA_ENABLE:-"false"}
CBWXPROXY_JAVA_PORT=${CBWXPROXY_JAVA_PORT:-"25565"}
CBWXPROXY_JAVA_REMOTE_HOST=${CBWXPROXY_JAVA_REMOTE_HOST:-""}
TRAEFIK_ADMIN_DEBUG=${TRAEFIK_ADMIN_DEBUG:="false"}
TRAEFIK_ADMIN_ENABLE=${TRAEFIK_ADMIN_ENABLE:-"false"}
TRAEFIK_ADMIN_PORT=${TRAEFIK_ADMIN_PORT:-"8888"}
TRAEFIK_LOG_LEVEL=${TRAEFIK_LOG_LEVEL:-"ERROR"}
TRAEFIK_ENTRYPOINTS_OPTS="\
entryPoints:
traefik:
address: \":${TRAEFIK_ADMIN_PORT}\"
"
config_bedrock() {
if [[ "x${CBWXPROXY_BEDROCK_ENABLE}" == "xtrue" ]]; then
if [[ "x${CBWXPROXY_BEDROCK_REMOTE_HOST}" == "x" ]]; then
echo "ERROR: CBWXPROXY_BEDROCK_ENABLE variable is 'true' but CBWXPROXY_BEDROCK_REMOTE_HOST variable is empty!"
exit 1
elif [[ "x${CBWXPROXY_BEDROCK_PORT}" != "x" ]]; then
if [[ "${CBWXPROXY_BEDROCK_PORT}" -lt 1 ]] && [[ "${CBWXPROXY_BEDROCK_PORT}" -gt 65535 ]]; then
echo "ERROR: CBWXPROXY_BEDROCK_PORT must be a number between 1-65535!"
exit 1
fi
fi
TRAEFIK_ENTRYPOINTS_BEDROCK="\
bedrock:
address: \":${CBWXPROXY_BEDROCK_PORT}/udp\"
"
TRAEFIK_BEDROCK_OPTS="\
udp:
routers:
bedrock:
entryPoints:
- \"bedrock\"
service: \"bedrock\"
services:
bedrock:
loadBalancer:
servers:
- address: \"${CBWXPROXY_BEDROCK_REMOTE_HOST}\"
"
fi
}
config_java() {
if [[ "x${CBWXPROXY_JAVA_ENABLE}" == "xtrue" ]]; then
if [[ "x${CBWXPROXY_JAVA_REMOTE_HOST}" == "x" ]]; then
echo "ERROR: CBWXPROXY_JAVA_ENABLE variable is 'true' but CBWXPROXY_JAVA_REMOTE_HOST variable is empty!"
exit 1
elif [[ "x${CBWXPROXY_JAVA_PORT}" != "x" ]]; then
if [[ "${CBWXPROXY_JAVA_PORT}" -lt 1 ]] && [[ "${CBWXPROXY_JAVA_PORT}" -gt 65535 ]]; then
echo "ERROR: CBWXPROXY_JAVA_PORT must be a number between 1-65535!"
exit 1
fi
fi
TRAEFIK_ENTRYPOINTS_JAVA="\
java:
address: \":${CBWXPROXY_JAVA_PORT}\"
"
TRAEFIK_JAVA_OPTS="\
tcp:
routers:
java:
entryPoints:
- \"java\"
rule: \"HostSNI(\`*\`)\"
service: \"java\"
services:
java:
loadBalancer:
servers:
- address: \"${CBWXPROXY_JAVA_REMOTE_HOST}\"
"
fi
}
config_traefik_admin() {
if [[ "x${TRAEFIK_ADMIN_ENABLE}" == "xtrue" ]]; then
if [[ "x${TRAEFIK_ADMIN_PORT}" != "x" ]]; then
if [[ "${TRAEFIK_ADMIN_PORT}" -lt 1 ]] && [[ "${TRAEFIK_ADMIN_PORT}" -gt 65535 ]]; then
echo "ERROR: TRAEFIK_ADMIN_PORT must be a number between 1-65535!"
exit 1
fi
fi
TRAEFIK_ADMIN_OPTS="\
api:
dashboard: true
debug: ${TRAEFIK_ADMIN_DEBUG}
insecure: true
"
fi
}
write_config() {
TRAEFIK_ENTRYPOINTS_OPTS=${TRAEFIK_ENTRYPOINTS_OPTS}${TRAEFIK_ENTRYPOINTS_BEDROCK}${TRAEFIK_ENTRYPOINTS_JAVA}
cat << EOF > /etc/traefik.yaml
# traefik.yaml
global:
checkNewVersion: false
sendAnonymousUsage: false
log:
level: "${TRAEFIK_LOG_LEVEL}"
accessLog: {}
ping:
entryPoint: "traefik"
providers:
file:
filename: /etc/provider.yaml
${TRAEFIK_ADMIN_OPTS}
${TRAEFIK_ENTRYPOINTS_OPTS}
EOF
cat << EOF > /etc/provider.yaml
${TRAEFIK_BEDROCK_OPTS}
${TRAEFIK_JAVA_OPTS}
EOF
}
#Check enabled
if [[ "x${CBWXPROXY_BEDROCK_ENABLE}" != "xtrue" ]] && [[ "x${CBWXPROXY_JAVA_ENABLE}" != "xtrue" ]]; then
echo "ERROR: Either CBWXPROXY_BEDROCK_ENABLE or CBWXPROXY_JAVA_ENABLE variable must be TRUE!"
exit 1
fi
#Check bedrock
config_bedrock
#Check java
config_java
#Check traefik admin
config_traefik_admin
#Write config file
write_config
exec traefik --configFile=/etc/traefik.yaml