-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-config.sh
executable file
·49 lines (42 loc) · 952 Bytes
/
build-config.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/dash
set -e
CERT_PATH=/etc/ssl/certs
KEY_PATH=/etc/ssl/keys
# Global config
echo "; Config auto-generated during Docker image build
foreground = yes
log = append
pid = /var/run/stunnel4/stunnel.pid
setuid = stunnel4
setgid = stunnel4
"
is_master=1
for service_key in $KEY_PATH/*.pem;
do
pem_filename=$( basename "$service_key" )
service_name_with_port="${pem_filename%.pem}"
service_name="${service_name_with_port%@*}"
port_part="${service_name_with_port#${service_name}}"
origin_port=${port_part#@}
origin_port=${origin_port:-80}
if [ $is_master ];
then
echo -n "
[master]
accept = 443"
is_master=''
else
echo -n "
[$service_name]
sni = master:$service_name"
fi
# Common config for both the master and the "slave" config sections
echo "
cert = $CERT_PATH/$pem_filename
key = $service_key
connect = $service_name:$origin_port
CAfile = /etc/ssl/certs/origin-pull-ca.pem
verifyChain = yes
TIMEOUTclose = 0
delay=yes"
done