From 8cb0a4eab6bd2d1d670cce3f95fd16d9b8055861 Mon Sep 17 00:00:00 2001 From: Rafael Alexandre Date: Wed, 23 Apr 2025 20:09:22 +0200 Subject: [PATCH] add --client-ip/-ip 'auto' option + fix default/empty peer name logic Signed-off-by: Rafael Alexandre --- scripts/wireguard/makeCONF.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/wireguard/makeCONF.sh b/scripts/wireguard/makeCONF.sh index 8257a12..62ce36b 100755 --- a/scripts/wireguard/makeCONF.sh +++ b/scripts/wireguard/makeCONF.sh @@ -32,12 +32,16 @@ helpFunc() { echo "::: Commands:" echo "::: [none] Interactive mode" echo "::: -n,--name Name for the Client (default: '${HOSTNAME}')" - echo "::: -ip,--client-ip IPv4 address of the Client" + echo "::: -ip,--client-ip IPv4 address of the Client ('auto' for automatically assigning IP)" echo "::: -h,--help Show this help dialog" } checkName() { # check name + if [[ -z "${CLIENT_NAME}" ]]; then + err "::: Name is blank. Defaulting to '${HOSTNAME}'." + CLIENT_NAME=$HOSTNAME + fi if [[ "${CLIENT_NAME}" =~ [^a-zA-Z0-9.@_-] ]]; then err "Name can only contain alphanumeric characters and these symbols (.-@_)." exit 1 @@ -56,14 +60,11 @@ checkName() { elif [[ "${#CLIENT_NAME}" -gt 15 ]]; then err "::: Names cannot be longer than 15 characters." exit 1 - elif [[ -z "${CLIENT_NAME}" ]]; then - err "::: You cannot leave the name blank." - exit 1 elif [[ "${CLIENT_NAME}" == "server" ]]; then err "Sorry, this is in use by the server and cannot be used by clients." exit 1 elif [[ -f "configs/${CLIENT_NAME}.conf" ]]; then - err "::: A client with this name already exists" + err "::: A client with this name already exists." exit 1 fi } @@ -167,7 +168,7 @@ if [[ -z "${CLIENT_IP}" ]]; then read -p "Enter the Client IP from range ${FIRST_IPV4} - ${LAST_IPV4} (optional): " CLIENT_IP fi -if [[ -n "${CLIENT_IP}" ]]; then +if [[ -n "${CLIENT_IP}" && "${CLIENT_IP}" != "auto" ]]; then checkClientIP "${CLIENT_IP}" ip="$(dotIPv4ToDec "${CLIENT_IP}")" @@ -194,7 +195,7 @@ else fi if [[ -z "${CLIENT_NAME}" ]]; then - read -r -p "Enter a Name for the Client: " CLIENT_NAME + read -r -p "Enter a Name for the Client (default: '${HOSTNAME}'): " CLIENT_NAME checkName else checkName