-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwg-pro.sh
executable file
·39 lines (33 loc) · 1.08 KB
/
wg-pro.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
#!/bin/sh
WIREGUARD_IP="./wireguard_ip"
WIREGUARD_CLIENTS="./wireguard_clients"
WIREGUARD_PRIVATE_KEY="./private_key"
rm -rf ./public
mkdir -p ./public
uci() {
echo "uci $@"
}
uci set network.wg0="interface"
uci set network.wg0.proto="wireguard"
uci set network.wg0.private_key="$(cat $WIREGUARD_PRIVATE_KEY)"
uci set network.wg0.listen_port="46761"
uci set network.wg0.addresses="$(cat $WIREGUARD_IP)"
if [ -e $WIREGUARD_CLIENTS ] && [ -f wireguard_ips ]; then
uci delete network wireguard_wg0
while read p; do
ip="$(echo $p | awk '{ print $1 }')"
pubkey="$(echo $p | awk '{ print $2 }')"
if [ -n "$pubkey" ]; then
pubkey_sha256="$(echo $pubkey | sha256sum)"
echo $ip > ./public/${pubkey_sha256%% *}
uci add network wireguard_wg0
uci set network.@wireguard_wg0[-1].public_key="$pubkey"
uci add_list network.@wireguard_wg0[-1].allowed_ips="$ip/32"
uci set network.@wireguard_wg0[-1].route_allowed_ips="1"
uci set network.@wireguard_wg0[-1].endpoint_port="51820"
fi
done < $WIREGUARD_CLIENTS
else
./ip-gen.sh "$(cat ip)" | tail -n +2 > $WIREGUARD_CLIENTS
fi
uci commit network