From 0a612774ac0fe2af6a6ce2f0ab8c70ec27702ae8 Mon Sep 17 00:00:00 2001 From: Stanislas Lange Date: Sun, 22 Jan 2023 12:30:06 +0100 Subject: [PATCH] Create client: fix check for existing IP and name Fix https://github.com/angristan/wireguard-install/issues/371 --- wireguard-install.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wireguard-install.sh b/wireguard-install.sh index b90b68e..e8f594b 100644 --- a/wireguard-install.sh +++ b/wireguard-install.sh @@ -284,9 +284,9 @@ function newClient() { read -rp "Client name: " -e CLIENT_NAME CLIENT_EXISTS=$(grep -c -E "^### Client ${CLIENT_NAME}\$" "/etc/wireguard/${SERVER_WG_NIC}.conf") - if [[ ${CLIENT_EXISTS} == '1' ]]; then + if [[ ${CLIENT_EXISTS} != 0 ]]; then echo "" - echo "A client with the specified name was already created, please choose another name." + echo -e "${ORANGE}A client with the specified name was already created, please choose another name.${NC}" echo "" fi done @@ -308,11 +308,11 @@ function newClient() { until [[ ${IPV4_EXISTS} == '0' ]]; do read -rp "Client 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") + IPV4_EXISTS=$(grep -c "$CLIENT_WG_IPV4/32" "/etc/wireguard/${SERVER_WG_NIC}.conf") - if [[ ${IPV4_EXISTS} == '1' ]]; then + if [[ ${IPV4_EXISTS} != 0 ]]; then echo "" - echo "A client with the specified IPv4 was already created, please choose another IPv4." + echo -e "${ORANGE}A client with the specified IPv4 was already created, please choose another IPv4.${NC}" echo "" fi done @@ -321,11 +321,11 @@ function newClient() { until [[ ${IPV6_EXISTS} == '0' ]]; do read -rp "Client 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") + IPV6_EXISTS=$(grep -c "${CLIENT_WG_IPV6}/128" "/etc/wireguard/${SERVER_WG_NIC}.conf") - if [[ ${IPV6_EXISTS} == '1' ]]; then + if [[ ${IPV6_EXISTS} != 0 ]]; then echo "" - echo "A client with the specified IPv6 was already created, please choose another IPv6." + echo -e "${ORANGE}A client with the specified IPv6 was already created, please choose another IPv6.${NC}" echo "" fi done