correction to work with first peer

This commit is contained in:
Charlie Root 2024-07-05 11:07:01 +02:00
parent b278771582
commit bad469b33e
3 changed files with 6 additions and 1 deletions

View File

@ -3,7 +3,7 @@
## Server
```sh
pkg_add wireguard-tools
pkg_add qrencode #optional
pkg_add libqrencode #optional
sh wireguard_server.sh
```
### For each client

View File

@ -14,11 +14,16 @@ client=$1
server_ip=$(curl ipinfo.io/ip)
interface="wg0"
config_file="/etc/wireguard/${interface}.conf"
interface_config_file="/etc/hostname.${interface}"
clients_dir="/etc/wireguard/clients"
server_port=$(grep "ListenPort" ${config_file} | awk '{print $3}')
last_ip=$(tail -n 1 ${config_file} |\
grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}")
if ! [ -n "$last_ip" ]; then
# if it's the first peer, config file don't have any IP
last_ip=$(head -n 1 ${interface_config_file} | grep -oE "([0-9]{1,3}\.){3}[0-9]{1,3}" | head -n 1)
fi
new_ip=$(echo "$last_ip" | awk -F. '{print $1"."$2"."$3"."$4+1}')
client_ip="${new_ip}/32"

0
wireguard_server.sh Normal file → Executable file
View File