wg_on_start last active Tunnel read on onstart.txt

This commit is contained in:
Désiré Werner Menrath 2023-11-19 18:08:47 +01:00
parent 9795a8c875
commit 7192047057
2 changed files with 10 additions and 2 deletions

View File

@ -24,8 +24,11 @@ export TEXTDOMAINDIR="/usr/share/locale"
WG_WDIR="/home/$USER/.config/wg_nmcli/" WG_WDIR="/home/$USER/.config/wg_nmcli/"
# Pfad wg Icons # Pfad wg Icons
WG_PIC="/home/$USER/.icons/" WG_PIC="/home/$USER/.icons/"
IFS=$'\n' WG_START=( $(cat ${WG_WDIR}onstart.txt) )
nmcli connection up "$WG_START"
nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' &> ${WG_WDIR}onstart.txt
ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') &> ${WG_WDIR}onstart.txt
case $LANG in case $LANG in
de_DE.UTF-8) OPEN=öffnen ;; de_DE.UTF-8) OPEN=öffnen ;;
@ -37,6 +40,7 @@ WG_PIC="/home/$USER/.icons/"
--text-align=center --no-buttons --auto-close \ --text-align=center --no-buttons --auto-close \
--timeout 1 \ --timeout 1 \
--text=$"<span color='#0fad0a'><b>"$ACTIVE"</b></span> <span><b>powered</b></span>" --text=$"<span color='#0fad0a'><b>"$ACTIVE"</b></span> <span><b>powered</b></span>"
# autoconnect wird hier abgeschalten damit auch neu importierte nach einem Systemneustart nicht aktiv sind # autoconnect wird hier abgeschalten damit auch neu importierte nach einem Systemneustart nicht aktiv sind
IFS=$'\n' lines=( $(cat ${WG_WDIR}tunnel.txt) ) IFS=$'\n' lines=( $(cat ${WG_WDIR}tunnel.txt) )
nmcli con mod "$lines" connection.autoconnect no nmcli con mod "$lines" connection.autoconnect no
@ -47,6 +51,7 @@ WG_PIC="/home/$USER/.icons/"
else else
chmod -x /home/"$USER"/.local/bin/wg_on_start chmod -x /home/"$USER"/.local/bin/wg_on_start
fi fi
yad --notification \ yad --notification \
--image="${WG_PIC}wg-vpn.png" \ --image="${WG_PIC}wg-vpn.png" \
--icon-size=32 --no-middle \ --icon-size=32 --no-middle \
@ -54,6 +59,7 @@ WG_PIC="/home/$USER/.icons/"
--menu="Wire-G $OPEN!/sbin/wire_g --menu="Wire-G $OPEN!/sbin/wire_g
|$ACTIVE stop!/sbin/wg_stop" \ |$ACTIVE stop!/sbin/wg_stop" \
--command="menu" & --command="menu" &
# Schreib die pid von Notify in # Schreib die pid von Notify in
pid=$(ps aux | grep yad | grep -v grep | awk '{print $2}') pid=$(ps aux | grep yad | grep -v grep | awk '{print $2}')
echo $pid > ${WG_WDIR}for-kill_pid.txt echo $pid > ${WG_WDIR}for-kill_pid.txt

4
wire_g
View File

@ -37,7 +37,9 @@ ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/
############################################################################################################ ############################################################################################################
wg_notify(){ wg_notify(){
ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') &> ${WG_WDIR}onstart.txt
nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' &> ${WG_WDIR}onstart.txt
ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
case $LANG in case $LANG in
de_DE.UTF-8) OPEN=öffnen ;; de_DE.UTF-8) OPEN=öffnen ;;