2024-08-26 08:22:03 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function disconnect() {
|
|
|
|
echo "Отключаю $1"
|
|
|
|
sudo wg-quick down "$1"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
function connect() {
|
|
|
|
echo "Подключаю frkn-$1"
|
|
|
|
sudo wg-quick up "frkn-$1"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
2024-08-27 06:39:01 +00:00
|
|
|
function in_array() {
|
|
|
|
local find=$1
|
|
|
|
shift
|
|
|
|
for e in "$@"; do
|
|
|
|
[[ "$e" == "$find" ]] && return 0
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2024-08-26 08:22:03 +00:00
|
|
|
country="$1"
|
2024-08-27 06:39:01 +00:00
|
|
|
countries=()
|
2024-08-26 08:22:03 +00:00
|
|
|
current=$(sudo wg show | head -n 1 | awk '{print $2}')
|
|
|
|
|
2024-08-27 06:39:01 +00:00
|
|
|
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
|
2024-08-26 08:22:03 +00:00
|
|
|
fi
|
|
|
|
|
2024-08-27 06:39:01 +00:00
|
|
|
case "$country" in
|
2024-08-26 08:22:03 +00:00
|
|
|
"down" )
|
|
|
|
if [ -n "$current" ]; then
|
|
|
|
disconnect "$current"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
|
|
|
|
"status"|"show" )
|
|
|
|
sudo wg show
|
|
|
|
;;
|
|
|
|
|
|
|
|
* )
|
|
|
|
if [ -n "$current" ]; then
|
|
|
|
disconnect "$current"
|
|
|
|
fi
|
|
|
|
connect "$country"
|
|
|
|
;;
|
|
|
|
esac
|