-
Notifications
You must be signed in to change notification settings - Fork 40
/
entry.sh
106 lines (71 loc) · 1.97 KB
/
entry.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
#!/usr/bin/env bash
set -e
_downwgcf() {
echo
echo "clean up"
if ! wg-quick down wgcf; then
echo "error down"
fi
echo "clean up done"
exit 0
}
#-4|-6
runwgcf() {
trap '_downwgcf' ERR TERM INT
_enableV4="1"
if [ "$1" = "-6" ]; then
_enableV4=""
fi
if [ ! -e "wgcf-account.toml" ]; then
wgcf register --accept-tos
fi
if [ ! -e "wgcf-profile.conf" ]; then
wgcf generate
fi
cp wgcf-profile.conf /etc/wireguard/wgcf.conf
DEFAULT_GATEWAY_NETWORK_CARD_NAME=`route | grep default | awk '{print $8}' | head -1`
DEFAULT_ROUTE_IP=`ifconfig $DEFAULT_GATEWAY_NETWORK_CARD_NAME | grep "inet " | awk '{print $2}' | sed "s/addr://"`
echo ${DEFAULT_GATEWAY_NETWORK_CARD_NAME}
echo ${DEFAULT_ROUTE_IP}
sed -i "/\[Interface\]/a PostDown = ip rule delete from $DEFAULT_ROUTE_IP lookup main" /etc/wireguard/wgcf.conf
sed -i "/\[Interface\]/a PostUp = ip rule add from $DEFAULT_ROUTE_IP lookup main" /etc/wireguard/wgcf.conf
if [ "$1" = "-6" ]; then
sed -i 's/AllowedIPs = 0.0.0.0/#AllowedIPs = 0.0.0.0/' /etc/wireguard/wgcf.conf
elif [ "$1" = "-4" ]; then
sed -i 's/AllowedIPs = ::/#AllowedIPs = ::/' /etc/wireguard/wgcf.conf
sed -i '/^Address = \([0-9a-fA-F]\{1,4\}:\)\{7\}[0-9a-fA-F]\{1,4\}\/[0-9]\{1,3\}/s/^/#/' /etc/wireguard/wgcf.conf
fi
modprobe ip6table_raw
wg-quick up wgcf
if [ "$_enableV4" ]; then
_checkV4
else
_checkV6
fi
echo
echo "OK, wgcf is up."
sleep infinity & wait
}
_checkV4() {
echo "Checking network status, please wait...."
while ! curl --max-time 2 ipinfo.io; do
wg-quick down wgcf
echo "Sleep 2 and retry again."
sleep 2
wg-quick up wgcf
done
}
_checkV6() {
echo "Checking network status, please wait...."
while ! curl --max-time 2 -6 ipv6.google.com; do
wg-quick down wgcf
echo "Sleep 2 and retry again."
sleep 2
wg-quick up wgcf
done
}
if [ -z "$@" ] || [[ "$1" = -* ]]; then
runwgcf "$@"
else
exec "$@"
fi