diff --git a/wireguard/make.sh b/wireguard/make.sh index a1438ef..5ec36ef 100755 --- a/wireguard/make.sh +++ b/wireguard/make.sh @@ -41,7 +41,7 @@ xread "Wireguard endpoint: " ENDPOINT DFL_ENDPOINT_PORT=${DFL_ENDPOINT_PORT:=51820} xread "Wireguard endpoint port: " ENDPOINT_PORT -CLIENT_IPS=10.42.1.0/16 +CLIENT_IPS=${CLIENT_IPS:-10.42.0.0/16} readVars diff --git a/wireguard/templates/root/Makefile b/wireguard/templates/root/Makefile index 4a0953f..6e36fa7 100644 --- a/wireguard/templates/root/Makefile +++ b/wireguard/templates/root/Makefile @@ -54,13 +54,13 @@ $(SERVER_CONF): $(SERVER_TPL) $(SERVER_KEY) -e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \ -e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \ -e 's/\$${\ALLOWED_IPS}/$(subst /,\/,$(ALLOWED_IPS))/g' \ - -e 's/\$${\CLIENT_IP}/$(subst /,\/,$(CLIENT_IP))/g' \ + -e 's/\$${\CLIENT_IP}/$(shell ./getFreeClientIP)\/$(patsubst %/,,$(CLIENT_IP))/g' \ -e 's/\$${\CLIENT_PRIVATE_KEY}/'$$(sed -e 's/\//\\\//g' "$(CLIENT_DIR)/$*_id")'/g' \ -e 's/\$${\SERVER_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(SERVER_PUBLIC_KEY)")'/g' \ > "$(CLIENT_DIR)/$*.conf" cat "$(SERVER_CLIENT_TPL)" \ | sed \ - -e 's/\$${\CLIENT_IP}/$(subst /,\/,$(CLIENT_IP))/g' \ + -e 's/\$${\CLIENT_IP}/$(shell ./getFreeClientIP)\/$(patsubst %/,,$(CLIENT_IP))/g' \ -e 's/\$${\ENDPOINT}/$(ENDPOINT)/g' \ -e 's/\$${\ENDPOINT_PORT}/$(ENDPOINT_PORT)/g' \ -e 's/\$${\CLIENT_PUBLIC_KEY}/'$$(sed -e 's/\//\\\//g' "$(CLIENT_DIR)/$*_id.pub")'/g' \ diff --git a/wireguard/templates/root/getFreeClientIP b/wireguard/templates/root/getFreeClientIP index c89d0e3..74cd778 100755 --- a/wireguard/templates/root/getFreeClientIP +++ b/wireguard/templates/root/getFreeClientIP @@ -2,8 +2,8 @@ CLIENT_IPS=${CLIENT_IPS} -BASE_IP=${CLIENT_IPS/0\/*} -IPs=($(cat /etc/wireguard/clients/* \ +BASE_IP=${CLIENT_IPS/.0\/*} +IPs=($(cat /etc/wireguard/clients/* 2> /dev/null \ | grep Address \ | cut -d'.' -f 4 \ | cut -d '/' -f 1 \