From 75f64c648e0d758a68574af6c35ab4f49baaa49a Mon Sep 17 00:00:00 2001 From: punix Date: Wed, 8 Nov 2023 17:53:22 +0100 Subject: [PATCH] test 6 import --- wire_g | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/wire_g b/wire_g index ddba674..79dac69 100755 --- a/wire_g +++ b/wire_g @@ -73,39 +73,41 @@ import_wg(){ a_user=$(whoami) wg_pic="/home/$a_user/.icons/" wg_wdir="/home/$a_user/.config/wg_nmcli/" - wgconf=$(yad --file --separator=" \n" \ + if wgconf=$(yad --file --separator=" \n" \ --button="OK" --button=$"Cancel" \ --width=1200 --height=800 \ --window-icon=${wg_pic}wg-import.png \ --title=$"Wireguard .conf Select file") + then + case "$wgconf" in - case "$wgconf" in - - *_*.conf) if grep -i 'PEER\|PublicKey' $wgconf > /dev/null && grep -i 'Interface\|PrivateKey' $wgconf > /dev/null - then - active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') - if [[ -n $active ]] + *_*.conf) if grep -i 'PEER\|PublicKey' $wgconf > /dev/null && grep -i 'Interface\|PrivateKey' $wgconf > /dev/null 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 + 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 ;; + fi + fi ;; - *) yad --text-align=center --button=$"OK" --title=$"Wireguard .conf Select file" \ - --image-on-top --image=${wg_pic}wg-info.png \ - --fixed --center --buttons-layout=center --borders=8 \ - --text $"Oh, something went wrong. \n + *) yad --text-align=center --button=$"OK" --title=$"Wireguard .conf Select file" \ + --image-on-top --image=${wg_pic}wg-info.png \ + --fixed --center --buttons-layout=center --borders=8 \ + --text $"Oh, something went wrong. \n No valid Wireguard file. \n -Here is an example: my_wireguard.conf \n" -more ;; - esac -} +Here is an example: my_wireguard.conf \n" +import_wg ;; + esac + else + exit 0 +fi } export -f import_wg # function end