From e483ddf816913d46788f3b73a8e9362a687151e7 Mon Sep 17 00:00:00 2001 From: punix Date: Fri, 17 Nov 2023 21:00:29 +0100 Subject: [PATCH] test import double 2 --- wire_g | 67 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/wire_g b/wire_g index 5ea7ca0..434af16 100755 --- a/wire_g +++ b/wire_g @@ -75,52 +75,51 @@ wg_notify(){ # funktion wireguard import import_wg(){ - + if WG_CONF=$(yad --file --separator=" \n" \ --button="OK" --button=$"Cancel" \ --width=1200 --height=800 --no-klick \ --window-icon=${WG_PIC}wg-import.png \ --title=$"Wireguard .conf Select file") - then - IFS=$'\n' lines=( $(cat ${WG_WDIR}tunnel.txt) ) - #echo ${lines[0]} #Damit wird der Inhalt ausgelesen. (Index angeben) - for WG_CONF in "${lines[@]}" - do + echo $WG_CONF > ${WG_WDIR}exist.txt + if grep -f ${WG_WDIR}tunnel.txt ${WG_WDIR}exist.txt + then yad --image-on-top --image=${WG_PIC}wg-info.png \ --text=$"Tunnel already exists!" \ - --text-align=center --no-buttons \ + --text-align=center --button "OK" \ --borders=8 --undecorated \ - --timeout 3 --timeout-indicator=bottom --skip-taskbar - import_wg - done - else - case "$WG_CONF" in + --timeout-indicator=bottom --skip-taskbar + import_wg + fi + + case "$WG_CONF" in - *_*.conf) if grep -i 'PEER\|PublicKey' $WG_CONF > /dev/null && grep -i 'Interface\|PrivateKey' $WG_CONF > /dev/null - then - ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') - if [[ -n $ACTIVE ]] - then - wg_stop - nmcli connection import type wireguard file $WG_CONF &> ${WG_WDIR}.tmp.txt - wait - wg_notify - else - kill $lines - nmcli connection import type wireguard file $WG_CONF &> ${WG_WDIR}.tmp.txt - wait - wg_notify - fi - fi ;; + *_*.conf) if grep -i 'PEER\|PublicKey' $WG_CONF > /dev/null && grep -i 'Interface\|PrivateKey' $WG_CONF > /dev/null + then + ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') + if [[ -n $ACTIVE ]] + then + wg_stop + nmcli connection import type wireguard file $WG_CONF &> ${WG_WDIR}.tmp.txt + wait + wg_notify + else + kill $lines + nmcli connection import type wireguard file $WG_CONF &> ${WG_WDIR}.tmp.txt + wait + wg_notify + fi + fi ;; - *) yad --image-on-top --image=${WG_PIC}wg-info.png --height=150 --width=240 \ - --text-align=center --undecorated --skip-taskbar \ - --borders=12 --button="OK" --buttons-layout=center --center \ - --text $"Oh, something went wrong. No valid Wireguard file. \n -Here is an example: my_wireguard.conf" + *) yad --image-on-top --image=${WG_PIC}wg-info.png --height=150 --width=240 \ + --text-align=center --undecorated --skip-taskbar \ + --borders=12 --button="OK" --buttons-layout=center --center \ + --text $"Oh, something went wrong. No valid Wireguard file. \n +Here is an example: my_wireguard.conf" import_wg ;; - esac + esac + fi } # function end