Support $AWG_INSTANCE environment variable

This commit is contained in:
E. S 2025-05-31 21:01:01 +03:00
parent ac96603d91
commit e22bca71a6

View File

@ -9,6 +9,11 @@ GREEN='\033[0;32m'
NC='\033[0m' NC='\033[0m'
AMNEZIAWG_DIR="/etc/amnezia/amneziawg" AMNEZIAWG_DIR="/etc/amnezia/amneziawg"
if [ -n "$AWG_INSTANCE" ]; then
PARAMS_FILE="/etc/amnezia/amneziawg/$AWG_INSTANCE.params"
else
PARAMS_FILE="/etc/amnezia/amneziawg/awg0.params"
fi
function isRoot() { function isRoot() {
if [ "${EUID}" -ne 0 ]; then if [ "${EUID}" -ne 0 ]; then
@ -152,7 +157,15 @@ function readH1AndH2AndH3AndH4() {
} }
function installQuestions() { function installQuestions() {
echo "AmneziaWG server installer (https://github.com/varckin/amneziawg-install)" local instance_label=
local default_ifname=awg0
if [ -n "$AWG_INSTANCE" ]; then
instance_label="($AWG_INSTANCE instance) "
default_ifname="awg_${AWG_INSTANCE/-/_}"
SERVER_AWG_NIC="$AWG_INSTANCE"
fi
echo "AmneziaWG server ${instance_label}installer (https://github.com/varckin/amneziawg-install)"
echo "" echo ""
echo "I need to ask you a few questions before starting the setup." echo "I need to ask you a few questions before starting the setup."
echo "You can keep the default options and just press enter if you are ok with them." echo "You can keep the default options and just press enter if you are ok with them."
@ -173,7 +186,7 @@ function installQuestions() {
done done
until [[ ${SERVER_AWG_NIC} =~ ^[a-zA-Z0-9_]+$ && ${#SERVER_AWG_NIC} -lt 16 ]]; do until [[ ${SERVER_AWG_NIC} =~ ^[a-zA-Z0-9_]+$ && ${#SERVER_AWG_NIC} -lt 16 ]]; do
read -rp "AmneziaWG interface name: " -e -i awg0 SERVER_AWG_NIC read -rp "AmneziaWG interface name: " -e -i $default_ifname SERVER_AWG_NIC
done done
until [[ ${SERVER_AWG_IPV4} =~ ^([0-9]{1,3}\.){3} ]]; do until [[ ${SERVER_AWG_IPV4} =~ ^([0-9]{1,3}\.){3} ]]; do
@ -317,7 +330,7 @@ SERVER_AWG_S2=${SERVER_AWG_S2}
SERVER_AWG_H1=${SERVER_AWG_H1} SERVER_AWG_H1=${SERVER_AWG_H1}
SERVER_AWG_H2=${SERVER_AWG_H2} SERVER_AWG_H2=${SERVER_AWG_H2}
SERVER_AWG_H3=${SERVER_AWG_H3} SERVER_AWG_H3=${SERVER_AWG_H3}
SERVER_AWG_H4=${SERVER_AWG_H4}" >"${AMNEZIAWG_DIR}/params" SERVER_AWG_H4=${SERVER_AWG_H4}" >"$PARAMS_FILE"
# Add server interface # Add server interface
echo "[Interface] echo "[Interface]
@ -599,7 +612,7 @@ function uninstallAmneziaWG() {
} }
function loadParams() { function loadParams() {
source "${AMNEZIAWG_DIR}/params" source "${PARAMS_FILE}"
SERVER_AWG_CONF="${AMNEZIAWG_DIR}/${SERVER_AWG_NIC}.conf" SERVER_AWG_CONF="${AMNEZIAWG_DIR}/${SERVER_AWG_NIC}.conf"
} }
@ -640,7 +653,7 @@ function manageMenu() {
initialCheck initialCheck
# Check if AmneziaWG is already installed and load params # Check if AmneziaWG is already installed and load params
if [[ -e "${AMNEZIAWG_DIR}/params" ]]; then if [[ -e "${PARAMS_FILE}" ]]; then
loadParams loadParams
manageMenu manageMenu
else else