From 298f3998d38dce0b3460412677f94ebe5ced754a Mon Sep 17 00:00:00 2001 From: punix Date: Mon, 30 Oct 2023 19:44:47 +0100 Subject: [PATCH] =?UTF-8?q?Bei=20import=20if=20-n=20$active=20hinzugef?= =?UTF-8?q?=C3=BCgt=20funktionen=20lesbarkeit=20angepasst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wire_g | 101 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/wire_g b/wire_g index 5185c11..74bd0a1 100755 --- a/wire_g +++ b/wire_g @@ -62,12 +62,19 @@ import_wg(){ --width=1200 --height=800 \ --window-icon=${wg_pic}wg-import.png \ --title="Wireguard .conf Datei auswählen") - if [ "$?" = "0" ] - then - wg_stop - nmcli connection import type wireguard file $wgconf > ${wg_wdir}.tmp.txt - wg_notify - fi } + if [ "$?" = "0" ] + then + active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') + if [ -n $active ] + then + wg_stop + nmcli connection import type wireguard file $wgconf > ${wg_wdir}.tmp.txt + wg_notify + else + nmcli connection import type wireguard file $wgconf > ${wg_wdir}.tmp.txt + wg_notify + fi + fi } export -f import_wg # function end @@ -89,29 +96,29 @@ remove(){ --button="OK" --button="Abbrechen" \ --separator="" --window-icon=${wg_pic}wg-trash.png \ --borders=8 --column 'Löschen' $tunnel) - if [ "$?" = "0" ] - then - nmcli connection delete $selection &> ${wg_wdir}.tmp.txt - success=$(grep -i "erfolgreich gelöscht" ${wg_wdir}.tmp.txt) - if [ "$?" = "0" ] - then - yad --window-icon=${wg_pic}wg-trash.png \ - --image-on-top --image=${wg_pic}wg-info.png \ - --text="Ihr Tunnel $selection wurde erfolgreich gelöscht.\n" \ - --text-align=center --button="OK" --title "Wire-G Trash" \ - --fixed --center --buttons-layout=center --borders=8 --center - else - yad --window-icon=${wg_pic}wg-trash.png \ - --image-on-top --image=${wg_pic}wg-info.png \ - --text="Oh etwas ging schief.\nBitte Tunnel im Networkmanager löschen." \ - --text-align=center --button="OK" --title "Wire-G Trash" \ - --fixed --center --buttons-layout=center --borders=8 --center - fi - if [ $selection = $active ] - then - pkill wire_g - pkill yad - fi + if [ "$?" = "0" ] + then + nmcli connection delete $selection &> ${wg_wdir}.tmp.txt + success=$(grep -i "erfolgreich gelöscht" ${wg_wdir}.tmp.txt) + if [ "$?" = "0" ] + then + yad --window-icon=${wg_pic}wg-trash.png \ + --image-on-top --image=${wg_pic}wg-info.png \ + --text="Ihr Tunnel $selection wurde erfolgreich gelöscht.\n" \ + --text-align=center --button="OK" --title "Wire-G Trash" \ + --fixed --center --buttons-layout=center --borders=8 --center + else + yad --window-icon=${wg_pic}wg-trash.png \ + --image-on-top --image=${wg_pic}wg-info.png \ + --text="Oh etwas ging schief.\nBitte Tunnel im Networkmanager löschen." \ + --text-align=center --button="OK" --title "Wire-G Trash" \ + --fixed --center --buttons-layout=center --borders=8 --center + fi + if [ $selection = $active ] + then + pkill wire_g + pkill yad + fi fi } export -f remove @@ -136,7 +143,7 @@ more(){ --button=Importieren:"bash -c import_wg" \ --button="Wire-G Stop":"bash -c wg_stop" \ --button="Abbrechen":1 \ - --separator="" --window-icon=${wg_pic}wg-vpn.png ) + --separator="" --window-icon=${wg_pic}wg-vpn.png) } export -f more # function end @@ -147,11 +154,11 @@ export -f more connect(){ success=$(grep -i "erfolgreich aktiviert" ${wg_wdir}.tmp.txt) - if [ "$?" = "0" ] + if [ "$?" = "0" ] then - nmcli con mod $selection connection.autoconnect no - wg_notify - fi } + nmcli con mod $selection connection.autoconnect no + wg_notify + fi } # function end ############################################################################################################ @@ -171,19 +178,19 @@ selection=$(yad --no-click --list \ Sollten keine Tunnel aufgelistet sein, so müssen sie ihren Tunnel zuvor importieren." \ --column 'Auswahl' $tunnel) - if [ "$?" = "0" ] - then - active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') - if [ -n $active ] - then - nmcli connection up $selection &> ${wg_wdir}.tmp.txt - connect - else - wg_stop - nmcli connection up $selection &> ${wg_wdir}.tmp.txt - connect - fi - fi +if [ "$?" = "0" ] + then + active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') + if [ -n $active ] + then + nmcli connection up $selection &> ${wg_wdir}.tmp.txt + connect + else + wg_stop + nmcli connection up $selection &> ${wg_wdir}.tmp.txt + connect + fi +fi ############################################ ENDE #########################################################