Bei import if -n $active hinzugefügt

funktionen lesbarkeit angepasst
This commit is contained in:
Désiré Werner Menrath 2023-10-30 19:44:47 +01:00
parent 5bebb7ccaf
commit 298f3998d3

101
wire_g
View File

@ -62,12 +62,19 @@ import_wg(){
--width=1200 --height=800 \ --width=1200 --height=800 \
--window-icon=${wg_pic}wg-import.png \ --window-icon=${wg_pic}wg-import.png \
--title="Wireguard .conf Datei auswählen") --title="Wireguard .conf Datei auswählen")
if [ "$?" = "0" ] if [ "$?" = "0" ]
then then
wg_stop active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
nmcli connection import type wireguard file $wgconf > ${wg_wdir}.tmp.txt if [ -n $active ]
wg_notify then
fi } 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 export -f import_wg
# function end # function end
@ -89,29 +96,29 @@ remove(){
--button="OK" --button="Abbrechen" \ --button="OK" --button="Abbrechen" \
--separator="" --window-icon=${wg_pic}wg-trash.png \ --separator="" --window-icon=${wg_pic}wg-trash.png \
--borders=8 --column 'Löschen' $tunnel) --borders=8 --column 'Löschen' $tunnel)
if [ "$?" = "0" ] if [ "$?" = "0" ]
then then
nmcli connection delete $selection &> ${wg_wdir}.tmp.txt nmcli connection delete $selection &> ${wg_wdir}.tmp.txt
success=$(grep -i "erfolgreich gelöscht" ${wg_wdir}.tmp.txt) success=$(grep -i "erfolgreich gelöscht" ${wg_wdir}.tmp.txt)
if [ "$?" = "0" ] if [ "$?" = "0" ]
then then
yad --window-icon=${wg_pic}wg-trash.png \ yad --window-icon=${wg_pic}wg-trash.png \
--image-on-top --image=${wg_pic}wg-info.png \ --image-on-top --image=${wg_pic}wg-info.png \
--text="Ihr Tunnel $selection wurde erfolgreich gelöscht.\n" \ --text="Ihr Tunnel $selection wurde erfolgreich gelöscht.\n" \
--text-align=center --button="OK" --title "Wire-G Trash" \ --text-align=center --button="OK" --title "Wire-G Trash" \
--fixed --center --buttons-layout=center --borders=8 --center --fixed --center --buttons-layout=center --borders=8 --center
else else
yad --window-icon=${wg_pic}wg-trash.png \ yad --window-icon=${wg_pic}wg-trash.png \
--image-on-top --image=${wg_pic}wg-info.png \ --image-on-top --image=${wg_pic}wg-info.png \
--text="Oh etwas ging schief.\nBitte Tunnel im Networkmanager löschen." \ --text="Oh etwas ging schief.\nBitte Tunnel im Networkmanager löschen." \
--text-align=center --button="OK" --title "Wire-G Trash" \ --text-align=center --button="OK" --title "Wire-G Trash" \
--fixed --center --buttons-layout=center --borders=8 --center --fixed --center --buttons-layout=center --borders=8 --center
fi fi
if [ $selection = $active ] if [ $selection = $active ]
then then
pkill wire_g pkill wire_g
pkill yad pkill yad
fi fi
fi } fi }
export -f remove export -f remove
@ -136,7 +143,7 @@ more(){
--button=Importieren:"bash -c import_wg" \ --button=Importieren:"bash -c import_wg" \
--button="Wire-G Stop":"bash -c wg_stop" \ --button="Wire-G Stop":"bash -c wg_stop" \
--button="Abbrechen":1 \ --button="Abbrechen":1 \
--separator="" --window-icon=${wg_pic}wg-vpn.png ) --separator="" --window-icon=${wg_pic}wg-vpn.png)
} }
export -f more export -f more
# function end # function end
@ -147,11 +154,11 @@ export -f more
connect(){ connect(){
success=$(grep -i "erfolgreich aktiviert" ${wg_wdir}.tmp.txt) success=$(grep -i "erfolgreich aktiviert" ${wg_wdir}.tmp.txt)
if [ "$?" = "0" ] if [ "$?" = "0" ]
then then
nmcli con mod $selection connection.autoconnect no nmcli con mod $selection connection.autoconnect no
wg_notify wg_notify
fi } fi }
# function end # function end
############################################################################################################ ############################################################################################################
@ -171,19 +178,19 @@ selection=$(yad --no-click --list \
<b>Sollten keine Tunnel aufgelistet sein,</b> <b>Sollten keine Tunnel aufgelistet sein,</b>
<b>so müssen sie ihren Tunnel zuvor importieren.</b>" \ <b>so müssen sie ihren Tunnel zuvor importieren.</b>" \
--column 'Auswahl' $tunnel) --column 'Auswahl' $tunnel)
if [ "$?" = "0" ] if [ "$?" = "0" ]
then then
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
if [ -n $active ] if [ -n $active ]
then then
nmcli connection up $selection &> ${wg_wdir}.tmp.txt nmcli connection up $selection &> ${wg_wdir}.tmp.txt
connect connect
else else
wg_stop wg_stop
nmcli connection up $selection &> ${wg_wdir}.tmp.txt nmcli connection up $selection &> ${wg_wdir}.tmp.txt
connect connect
fi fi
fi fi
############################################ ENDE ######################################################### ############################################ ENDE #########################################################