aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislas Lange <git@slange.me>2023-01-22 12:30:06 +0100
committerStanislas Lange <git@slange.me>2023-01-22 12:30:06 +0100
commit0a612774ac0fe2af6a6ce2f0ab8c70ec27702ae8 (patch)
treeec935366d57b0cb4f086e9f4d93efe77c7fece2d
parent77185dcdf8ae735adc8dafab67536dab66abadac (diff)
Create client: fix check for existing IP and name
Fix https://github.com/angristan/wireguard-install/issues/371
-rw-r--r--wireguard-install.sh16
1 files 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