From 3f0ce7949fb245128086138e4bd80b7e73782948 Mon Sep 17 00:00:00 2001 From: "E. S" Date: Sat, 31 May 2025 20:46:22 +0300 Subject: [PATCH] Support WG_INSTANCE environment variable --- wireguard-install.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/wireguard-install.sh b/wireguard-install.sh index 822e845..920fa0f 100644 --- a/wireguard-install.sh +++ b/wireguard-install.sh @@ -8,6 +8,12 @@ ORANGE='\033[0;33m' GREEN='\033[0;32m' NC='\033[0m' +if [ -n "$WG_INSTANCE" ]; then + PARAMS_FILE="/etc/wireguard/$WG_INSTANCE.params" +else + PARAMS_FILE=/etc/wireguard/wg0.params +fi + function isRoot() { if [ "${EUID}" -ne 0 ]; then echo "You need to run this script as root" @@ -122,6 +128,14 @@ function initialCheck() { function installQuestions() { echo "Welcome to the WireGuard installer!" + local instance_label= + local default_ifname=wg0 + if [ -n "$WG_INSTANCE" ]; then + instance_label="($WG_INSTANCE instance) " + default_ifname="wg_${WG_INSTANCE/-/_}" + SERVER_WG_NIC="$WG_INSTANCE" + fi + echo "Welcome to the WireGuard ${instance_label}installer!" echo "The git repository is available at: https://github.com/angristan/wireguard-install" echo "" echo "I need to ask you a few questions before starting the setup." @@ -143,7 +157,7 @@ function installQuestions() { done until [[ ${SERVER_WG_NIC} =~ ^[a-zA-Z0-9_]+$ && ${#SERVER_WG_NIC} -lt 16 ]]; do - read -rp "WireGuard interface name: " -e -i wg0 SERVER_WG_NIC + read -rp "WireGuard interface name: " -e -i $default_ifname SERVER_WG_NIC done until [[ ${SERVER_WG_IPV4} =~ ^([0-9]{1,3}\.){3} ]]; do @@ -247,7 +261,7 @@ SERVER_PRIV_KEY=${SERVER_PRIV_KEY} SERVER_PUB_KEY=${SERVER_PUB_KEY} CLIENT_DNS_1=${CLIENT_DNS_1} CLIENT_DNS_2=${CLIENT_DNS_2} -ALLOWED_IPS=${ALLOWED_IPS}" >/etc/wireguard/params +ALLOWED_IPS=${ALLOWED_IPS}" >"$PARAMS_FILE" # Add server interface echo "[Interface] @@ -578,8 +592,8 @@ function manageMenu() { initialCheck # Check if WireGuard is already installed and load params -if [[ -e /etc/wireguard/params ]]; then - source /etc/wireguard/params +if [[ -e "$PARAMS_FILE" ]]; then + source "$PARAMS_FILE" manageMenu else installWireGuard