aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislas Lange <stanislas.lange@pm.me>2021-03-18 14:03:25 +0100
committerStanislas Lange <stanislas.lange@pm.me>2021-03-18 14:03:25 +0100
commitbd37d606f1c77a3c74c8fe76d21ac0db1391d64c (patch)
treefb313d6eee00ad0e40bc3a10d6375af7d38b94a8
parent9fae7ad587d47960e565ca55d5da50a4c2460f3b (diff)
Improve IP parsing (fix #204)
-rw-r--r--wireguard-install.sh14
1 files changed, 8 insertions, 6 deletions
diff --git a/wireguard-install.sh b/wireguard-install.sh
index ebd4af0..68585b1 100644
--- a/wireguard-install.sh
+++ b/wireguard-install.sh
@@ -245,10 +245,11 @@ function newClient() {
exit 1
fi
+ BASE_IP=$(echo "$SERVER_WG_IPV4" | awk -F '.' '{ print $1"."$2"."$3 }')
until [[ ${IPV4_EXISTS} == '0' ]]; do
- read -rp "Client's WireGuard IPv4: ${SERVER_WG_IPV4::-1}" -e -i "${DOT_IP}" DOT_IP
- CLIENT_WG_IPV4="${SERVER_WG_IPV4::-1}${DOT_IP}"
- IPV4_EXISTS=$(grep -c "$CLIENT_WG_IPV4" "/etc/wireguard/${SERVER_WG_NIC}.conf")
+ read -rp "Client's WireGuard IPv4: ${BASE_IP}." -e -i "${DOT_IP}" DOT_IP
+ CLIENT_WG_IPV4="${BASE_IP}.${DOT_IP}"
+ IPV4_EXISTS=$(grep -c "$CLIENT_WG_IPV4/24" "/etc/wireguard/${SERVER_WG_NIC}.conf")
if [[ ${IPV4_EXISTS} == '1' ]]; then
echo ""
@@ -257,10 +258,11 @@ function newClient() {
fi
done
+ BASE_IP=$(echo "$SERVER_WG_IPV6" | awk -F '::' '{ print $1 }')
until [[ ${IPV6_EXISTS} == '0' ]]; do
- read -rp "Client's WireGuard IPv6: ${SERVER_WG_IPV6::-1}" -e -i "${DOT_IP}" DOT_IP
- CLIENT_WG_IPV6="${SERVER_WG_IPV6::-1}${DOT_IP}"
- IPV6_EXISTS=$(grep -c "${CLIENT_WG_IPV6}" "/etc/wireguard/${SERVER_WG_NIC}.conf")
+ read -rp "Client's WireGuard IPv6: ${BASE_IP}::" -e -i "${DOT_IP}" DOT_IP
+ CLIENT_WG_IPV6="${BASE_IP}::${DOT_IP}"
+ IPV6_EXISTS=$(grep -c "${CLIENT_WG_IPV6}/64" "/etc/wireguard/${SERVER_WG_NIC}.conf")
if [[ ${IPV6_EXISTS} == '1' ]]; then
echo ""