From 890f09b82b4df3f575cd8de09bd33010e81e1dbe Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Mon, 26 Aug 2024 16:22:03 +0800 Subject: [PATCH] frkn tool script for quick connection control --- tools/frkn.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 tools/frkn.sh diff --git a/tools/frkn.sh b/tools/frkn.sh new file mode 100755 index 0000000..3d4f089 --- /dev/null +++ b/tools/frkn.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +function disconnect() { + echo "Отключаю $1" + sudo wg-quick down "$1" + echo +} + +function connect() { + echo "Подключаю frkn-$1" + sudo wg-quick up "frkn-$1" + echo +} + +country="$1" +countries=(uk ru nl nl2 ch) +current=$(sudo wg show | head -n 1 | awk '{print $2}') + +if [ -z "$country" ]; then + IFS= read -rp "Выбери страну (${countries[*]}): " country +fi + +case $country in + "down" ) + if [ -n "$current" ]; then + disconnect "$current" + fi + ;; + + "status"|"show" ) + sudo wg show + ;; + + * ) + if [ -n "$current" ]; then + disconnect "$current" + fi + connect "$country" + ;; +esac