-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.sh
executable file
·52 lines (45 loc) · 1.12 KB
/
start.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
#!/bin/sh
createConf() {
if [ -z "$EXTERNAL_IP" ]; then
ip_tmp=$(curl http://icanhazip.com)
if [ $? -eq 0 ]; then
echo "获取 EXTERNAL_IP 成功: $ip_tmp"
EXTERNAL_IP="$ip_tmp"
else
echo "获取 EXTERNAL_IP 失败,请手动修改"
EXTERNAL_IP="0.0.0.0"
fi
else
echo "EXTERNAL_IP 已经设置为: $EXTERNAL_IP"
fi
cat <<EOF >>/etc/turnserver.conf
listening-device=eth0
listening-port=3478
listening-ip=$listening_ip
external-ip=$EXTERNAL_IP
fingerprint
lt-cred-mech
user=$user_tmp
realm=$listening_ip
no-tlsv1
no-tlsv1_1
no-tlsv1_2
EOF
}
getEth0Ip() {
ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1
}
echo "====== 配置 turnserver ======"
user_tmp=${TURN_USERNAME:-"user"}:${TURN_PASSWORD:-"pass"}
listening_ip=$(getEth0Ip)
if [ ! -f /etc/turnserver.conf ]; then
echo "创建 /etc/turnserver.conf 配置文件"
createConf
echo "====== 启动 turnserver ======"
echo "external-ip=$EXTERNAL_IP"
echo "user=$user_tmp"
else
echo "/etc/turnserver.conf 配置文件已存在"
echo "====== 启动 turnserver ======"
fi
exec turnserver -c /etc/turnserver.conf