From 7426347bcd4829aed0ad25fefd9bcf05ae7c43c9 Mon Sep 17 00:00:00 2001
From: randomshell <randshell@protonmail.com>
Date: Thu, 2 Jul 2020 15:36:35 +0000
Subject: [PATCH] Ask user for client name

---
 wireguard-install.sh | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/wireguard-install.sh b/wireguard-install.sh
index 40c08ce..c465a5e 100644
--- a/wireguard-install.sh
+++ b/wireguard-install.sh
@@ -12,6 +12,13 @@ function addClient() {
 		ENDPOINT="$SERVER_PUB_IP:$SERVER_PORT"
 	fi
 
+	echo ""
+	echo "Tell me a name for the client."
+	echo "Use one word only, no special characters."
+	until [[ "$CLIENT_NAME" =~ ^[a-zA-Z0-9_]+$ ]]; do
+		read -rp "Client name: " -e CLIENT_NAME
+	done
+
 	CLIENT_WG_IPV4="10.66.66.2"
 	read -rp "Client's WireGuard IPv4 " -e -i "$CLIENT_WG_IPV4" CLIENT_WG_IPV4
 
@@ -25,11 +32,6 @@ function addClient() {
 	CLIENT_DNS_2="176.103.130.131"
 	read -rp "Second DNS resolver to use for the client: " -e -i "$CLIENT_DNS_2" CLIENT_DNS_2
 
-	CLIENT_NAME=$(
-		head /dev/urandom | tr -dc A-Za-z0-9 | head -c 10
-		echo ''
-	)
-
 	# Generate key pair for the client
 	CLIENT_PRIV_KEY=$(wg genkey)
 	CLIENT_PUB_KEY=$(echo "$CLIENT_PRIV_KEY" | wg pubkey)