-
Notifications
You must be signed in to change notification settings - Fork 5
/
start.sh
executable file
·52 lines (41 loc) · 1.18 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/bash
# 判断tun0是否存在的
if [ -e /dev/net/tun ]; then
:
else
echo "/dev/net/tun doesn't exist. Please create it first." >&2
exit 1
fi
# 定义一个处理函数,用于在接收到 INT 信号时退出脚本
function cleanup {
echo "Exiting script..."
exit 0
}
# 捕获 INT 信号,并调用 cleanup 函数
trap cleanup INT
sed -i "s/{{server_address}}/$SERVER_ADDRESS/g" expect.exp
sed -i "s/{{user_name}}/$USER_NAME/g" expect.exp
sed -i "s/{{password}}/$PASSWORD/g" expect.exp
cd /opt/TopSAP && ./sv_websrv >/home/work/sv_websrv.log 2>&1 &
sleep 1
expect -f expect.exp
for i in {1..3}; do
if [ -e "/sys/class/net/tun0" ]; then
# 如果设备存在,跳出循环
danted -f /etc/danted.conf &
break
else
# 如果设备不存在,等待三秒后进行下一次判断
sleep 3
fi
done
# 循环结束后判断设备是否存在
if [ ! -e "/sys/class/net/tun0" ]; then
echo "Device tun0 not found."
exit 1
fi
# 更改MTU(与 topsap 的默认值保持一致)
ip link set dev tun0 mtu 1300
# 添加NAT转发,使其他请求可以走正常出口,不全部走代理,例如公网请求
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
wait