diff --git a/wireguard/templates/root/Makefile b/wireguard/templates/root/Makefile index 7e43f00..9d80230 100644 --- a/wireguard/templates/root/Makefile +++ b/wireguard/templates/root/Makefile @@ -21,6 +21,10 @@ ALLOWED_IPS ?= 0.0.0.0/0 CLIENT_IP ?= 10.42.0.1/32 +test: + $(call newIP) + + %_id: @ mkdir -p $$(dirname $@) wg genkey 2> /dev/null > $@ diff --git a/wireguard/templates/root/getFreeClientIP b/wireguard/templates/root/getFreeClientIP new file mode 100755 index 0000000..ca175dc --- /dev/null +++ b/wireguard/templates/root/getFreeClientIP @@ -0,0 +1,19 @@ +#!/usr/bin/bash + +CLIENT_IPS=${CLIENT_IPS} + +BASE_IP=${CLIENT_IPS/0\/*} +IPs=($(cat /etc/wireguard/clients/* \ + | grep Address \ + | cut -d'.' -f 4 \ + | cut -d '/' -f 1 \ + | sort)) +IPs=${IPs[@]} + +i=1 +while [ "$( echo $IPs | fgrep -w $i )" ] ; do + i=$(( i + 1 )) +done + +echo $BASE_IP.$i +