You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib.sh
+9-5Lines changed: 9 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -46,12 +46,15 @@ sudo() {
46
46
fi
47
47
}
48
48
49
+
# shellcheck disable=SC2120
49
50
wg() {
50
-
if$CLS_DOCKER;then
51
-
sudo docker exec wireguard wg "$@"
52
-
else
53
-
command wg "$@"
54
-
fi
51
+
sudo bash <<EOF
52
+
if [ "$CLS_DOCKER" = "true" ]; then
53
+
docker exec wireguard wg ${@@Q}
54
+
else
55
+
command wg ${@@Q}
56
+
fi
57
+
EOF
55
58
}
56
59
57
60
get_local_iface() {
@@ -64,6 +67,7 @@ get_local_ip() {
64
67
ip r | grep -q '^default via'|| sudo ip r add default via "$(nmcli dev show "$CLS_LOCAL_IFACE"| grep -oP '((?<=GATEWAY:)[^-]*|/0.*?= [^,]+)'| grep -oE '[^ ]+$'| head -n1)" dev "$CLS_LOCAL_IFACE"&>/dev/null
65
68
CLS_GATEWAY=$(ip r | grep -oP '^default via \K\S+')
66
69
CLS_LOCAL_IP=$(ip a show "$CLS_LOCAL_IFACE"| grep -oP 'inet \K\S+'| cut -d/ -f1)
@@ -70,7 +70,7 @@ if ! ${CLS_WG_ONLY:-false}; then
70
70
eval"start_hostapd ${*@Q}"&
71
71
fi
72
72
73
-
if$CLS_DOCKER;then
73
+
if[ "$CLS_DOCKER"="true" ];then
74
74
sudo systemctl enable --now docker
75
75
76
76
fortablein nat filter;do
@@ -82,7 +82,7 @@ if $CLS_DOCKER; then
82
82
else
83
83
sudo sysctl -w net.ipv4.ip_forward=0
84
84
sudo sysctl -w net.ipv6.conf.all.forwarding=0
85
-
forifacein$(sudo wg | grep -oP '(?<=interface: ).+');do sudo wg-quick down "$iface";done
85
+
forifacein$(wg | grep -oP '(?<=interface: ).+');do sudo wg-quick down "$iface";done
86
86
fi
87
87
88
88
eval"cast pre-up ${*@Q}"
@@ -104,17 +104,11 @@ eval "cast pre-up ${*@Q}"
104
104
get_local_ip
105
105
106
106
if! ip rule show table 7 2>/dev/null | grep -qP '0x55'||! ip route show table 7 2>/dev/null | grep -q default;then
107
-
ip route show table 7 2>/dev/null | grep -q default || sudo ip route add default via "$(ip r | grep -oP 'default via \K\S+')" dev "$CLS_LOCAL_IFACE" table 7 &>/dev/null
107
+
ip route show table 7 2>/dev/null | grep -q default || sudo ip route add default via "$CLS_GATEWAY" dev "$CLS_LOCAL_IFACE" table 7 &>/dev/null
108
108
ip rule show table 7 2>/dev/null | grep -qP '0x55'|| sudo ip rule add fwmark 0x55 table 7 &>/dev/null
109
109
sudo ip route flush cache
110
110
fi
111
111
112
-
if [ -n"$CLS_EXTERN_IFACE" ] && [[ "$CLS_TYPE_NODE"=~ (hub|saah) ]] && ip a show "$CLS_EXTERN_IFACE"| grep -q UP;then
0 commit comments