From 737da43522536bdc5e96ff973f1bd4bb9ffeba97 Mon Sep 17 00:00:00 2001 From: Anthony Axenov Date: Tue, 27 Aug 2024 14:39:01 +0800 Subject: [PATCH] Updated frkn tool --- tools/frkn.sh | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tools/frkn.sh b/tools/frkn.sh index 3d4f089..8f1bd66 100755 --- a/tools/frkn.sh +++ b/tools/frkn.sh @@ -12,15 +12,38 @@ function connect() { echo } +function in_array() { + local find=$1 + shift + for e in "$@"; do + [[ "$e" == "$find" ]] && return 0 + done + return 1 +} + country="$1" -countries=(uk ru nl nl2 ch) +countries=() current=$(sudo wg show | head -n 1 | awk '{print $2}') -if [ -z "$country" ]; then - IFS= read -rp "Выбери страну (${countries[*]}): " country +for file in /etc/wireguard/*.conf; do + filename=${file/\/etc\/wireguard\/frkn-} + code=${filename/.conf/} + countries+=($code) +done + +correct=-1 +if [ -z "$country" ] ; then + while [ $correct -lt 0 ]; do + read -rp "Выбери страну (${countries[*]}): " country + if in_array "$country" ${countries[@]}; then + correct=1 + else + echo "Неверный код страны!" + fi + done fi -case $country in +case "$country" in "down" ) if [ -n "$current" ]; then disconnect "$current"