variablen und ifs gequotet

This commit is contained in:
Désiré Werner Menrath 2023-11-01 11:11:18 +01:00
parent a1048076b5
commit e4b04c481b
2 changed files with 38 additions and 39 deletions

View File

@ -7,18 +7,17 @@
wg_wdir="/home/$a_user/.config/wg_nmcli/"
wg_pic="/home/$a_user/.icons/"
#Damit wird der inhalt von /home/$a_user/.config/wg_nmcli/.tunnel.txt in ein Array gespeichert
IFS=$'\n' lines=( $(cat ${wg_wdir}.tunnel.txt) )
IFS=$'\n' lines=( "$(cat "${wg_wdir}.tunnel.txt")" )
#echo ${lines[0]} #Damit wird der Inhalt ausgelesen. (Index angeben)
wert=$"*_*"
for wert in "${lines[@]}"
do
# rm /home/$a_user/.config/wg_nmcli/.tunnel.txt # falls Wireguard nicht richtig funktioniert hier die # wegnehmen
# hier wird die Ausgabe von nmcli für die auswertung in die .stop.txt gespeichert
nmcli connection down $wert &> ${wg_wdir}.stop.txt
disable=$(grep -i "deaktiviert" ${wg_wdir}.stop.txt)
if [ "$?" = "0" ]
nmcli connection down "$wert" &> "${wg_wdir}.stop.txt"
if disable=$(grep -i '"deaktiviert"\|"disabled"' "${wg_wdir}.stop.txt")
then
notify-send --icon=${wg_pic}wg-stop.png "$wert Connection disconnected."
notify-send --icon="${wg_pic}wg-stop.png" "$wert Connection disconnected."
pkill yad
fi

64
wire_g
View File

@ -11,7 +11,7 @@ wg_wdir="/home/$a_user/.config/wg_nmcli/"
wg_pic="/home/$a_user/.icons/"
# Wireguard tunnel auslesen mit grep nur Wireguard zeigen
# mit sed alles nach dem ersten Leerzeichen bis Zeilenende weggeschneiden und .tunnel.txt schreiben
nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' > ${wg_wdir}.tunnel.txt
nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' > "${wg_wdir}.tunnel.txt"
# Variable der verfügbaren Tunnelanzeige für Yad
tunnel=$(nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
# Variable der aktiven Tunnelanzeige für Yad
@ -26,15 +26,15 @@ wg_notify(){
a_user=$(whoami)
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
wg_pic="/home/$a_user/.icons/"
notify-send --icon=${wg_pic}wg-vpn.png "$active powered"
notify-send --icon="${wg_pic}wg-vpn.png" "$active powered"
# autoconnect wird hier abgeschalten damit auch neu importierte nach einem Systemneustart nicht aktiv sind
nmcli con mod $active connection.autoconnect no
nmcli con mod "$active" connection.autoconnect no
# ab hier beginnt yad notify
#Pipe erstellen
PIPE="$HOME/.pipe.tmp"
rm $PIPE > /dev/null 2>&1
mkfifo $PIPE
exec 3<> $PIPE
rm "$PIPE" > /dev/null 2>&1
mkfifo "$PIPE"
exec 3<> "$PIPE"
#Yad Dialog erstellen
yad --notification --listen --command=wire_g --icon-size=32 --no-middle <&3 &
#Menüeinträge definieren
@ -60,18 +60,18 @@ import_wg(){
wgconf=$(yad --file --separator=" \n" \
--button="OK" --button="Cancel" \
--width=1200 --height=800 \
--window-icon=${wg_pic}wg-import.png \
--window-icon="${wg_pic}wg-import.png" \
--title="Wireguard .conf Select file")
if [ "$?" = "0" ]
then
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
if [ -n $active ]
if [ -n "$active" ]
then
wg_stop
nmcli connection import type wireguard file $wgconf > ${wg_wdir}.tmp.txt
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
nmcli connection import type wireguard file "$wgconf" > "${wg_wdir}.tmp.txt"
wg_notify
fi
fi }
@ -87,34 +87,34 @@ remove(){
wg_pic="/home/$a_user/.icons/"
wg_wdir="/home/$a_user/.config/wg_nmcli/"
tunnel=$(nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' &> ${wg_wdir}.wg_noactive.txt
active=$(cat ${wg_wdir}.wg_noactive.txt)
nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' &> "${wg_wdir}.wg_noactive.txt"
active=$(cat "${wg_wdir}.wg_noactive.txt")
selection=$(yad --no-click --list --height=300 --width=60 \
--title="Wire-G Trash" --center \
--fixed --buttons-layout=center \
--button="OK" --button="Cancel" \
--separator="" --window-icon=${wg_pic}wg-trash.png \
--borders=8 --column 'Delete' $tunnel)
--separator="" --window-icon="${wg_pic}wg-trash.png" \
--borders=8 --column 'Delete' "$tunnel")
if [ "$?" = "0" ]
then
nmcli connection delete $selection &> ${wg_wdir}.tmp.txt
success=$(grep -i '"erfolgreich gelöscht"\|"successfully deleted"' ${wg_wdir}.tmp.txt)
nmcli connection delete "$selection" &> "${wg_wdir}.tmp.txt"
success=$(grep -i '"erfolgreich gelöscht"\|"successfully deleted"' "${wg_wdir}.tmp.txt")
if [ "$?" = "0" ]
then
yad --window-icon=${wg_pic}wg-trash.png \
--image-on-top --image=${wg_pic}wg-info.png \
yad --window-icon="${wg_pic}wg-trash.png" \
--image-on-top --image="${wg_pic}wg-info.png" \
--text="Your tunnel $selection was successfully deleted.\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 \
yad --window-icon="${wg_pic}wg-trash.png" \
--image-on-top --image="${wg_pic}wg-info.png" \
--text="Oh something went wrong.\nPlease delete tunnel in the network manager." \
--text-align=center --button="OK" --title "Wire-G Trash" \
--fixed --center --buttons-layout=center --borders=8 --center
fi
if [ $selection = $active ]
if [ "$selection" = "$active" ]
then
pkill wire_g
pkill yad
@ -128,9 +128,9 @@ export -f remove
#funktion for active tunnel a stop
up_or_down(){
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
if [ -z $active ]
if [ -z "$active" ]
then
yad --image-on-top --image=${wg_pic}wg-info.png \
yad --image-on-top --image="${wg_pic}wg-info.png" \
--text="There is no active tunnel that you could stop.\n" \
--text-align=center --button="OK" --title "Wire-G" \
--fixed --center --buttons-layout=center --borders=8 --center
@ -161,7 +161,7 @@ more(){
--button=Import:"bash -c import_wg" \
--button="Wire-G Stop":up_or_down \
--button="Cancel":1 \
--separator="" --window-icon=${wg_pic}wg-vpn.png)
--separator="" --window-icon="${wg_pic}wg-vpn.png")
}
export -f more
@ -172,10 +172,10 @@ export -f more
connect(){
success=$(grep -i '"erfolgreich aktiviert"\|"successfully activated"' ${wg_wdir}.tmp.txt)
success=$(grep -i '"erfolgreich aktiviert"\|"successfully activated"' "${wg_wdir}.tmp.txt")
if [ "$?" = "0" ]
then
nmcli con mod $selection connection.autoconnect no
nmcli con mod "$selection" connection.autoconnect no
wg_notify
fi }
@ -190,23 +190,23 @@ selection=$(yad --no-click --list \
--fixed --buttons-layout=center \
--button="OK" --button="Cancel" \
--button=More:"bash -c more" --button=Remove:"bash -c remove" --separator="" \
--window-icon=${wg_pic}wg-vpn.png \
--borders=8 --image-on-top --image=${wg_pic}wg-active.png \
--window-icon="${wg_pic}wg-vpn.png" \
--borders=8 --image-on-top --image="${wg_pic}wg-active.png" \
--text "<b>Activ Tunnel: </b> <span color='#0fad0a'><b>$active</b></span>
<b>----------------------------------------------------------------------------------</b>
<b>If no tunnels are listed,</b>
<b>so they have to import their tunnel beforehand.</b>" \
--column 'Selection' $tunnel)
--column 'Selection' "$tunnel")
if [ "$?" = "0" ]
then
if [ -n $active ]
if [ -n "$active" ]
then
wg_stop
nmcli connection up $selection &> ${wg_wdir}.tmp.txt
nmcli connection up "$selection" &> "${wg_wdir}.tmp.txt"
connect
else
nmcli connection up $selection &> ${wg_wdir}.tmp.txt
nmcli connection up "$selection" &> "${wg_wdir}.tmp.txt"
connect
fi
fi