Variablen alle großschreibung (zwischencommit)

This commit is contained in:
Désiré Werner Menrath 2023-11-14 19:54:51 +01:00
parent f23c9e1caf
commit 19aa3c3a42
4 changed files with 98 additions and 106 deletions

View File

@ -13,28 +13,26 @@
############################################################################################################ ############################################################################################################
############################################################################################################ ############################################################################################################
# Angemeldeten Benutzer ermitteln
a_user=$(whoami)
# abfrage ob benötigte pakete installiert sind, wenn nicht dann installiere automatisch die benötigten Pakete. # abfrage ob benötigte pakete installiert sind, wenn nicht dann installiere automatisch die benötigten Pakete.
if grep -i 'mint\|debian\|ubuntu\|pop|' /etc/os-release > /dev/null 2>&1 if grep -i 'mint\|debian\|ubuntu\|pop|' /etc/os-release > /dev/null 2>&1
then then
echo Wire-G wird installiert... echo Wire-G wird installiert...
mkdir -p /home/"$a_user"/.icons ; cp icons/* /home/"$a_user"/.icons/ ; mkdir -p /home/"$a_user"/.config/wg_nmcli mkdir -p /home/"$USER"/.icons ; cp icons/* /home/"$USER"/.icons/ ; mkdir -p /home/"$USER"/.config/wg_nmcli
if ! which yad > /dev/null ; then sudo apt install yad -y > /dev/null 2>&1 ; echo yad wird installiert. Bitte warten... ; fi if ! which yad > /dev/null ; then sudo apt install yad -y > /dev/null 2>&1 ; echo yad wird installiert. Bitte warten... ; fi
if ! which notify-send > /dev/null ; then sudo apt install libnotify-bin -y > /dev/null 2>&1 ; echo libnotify wird installiert. Bitte warten... ; fi if ! which notify-send > /dev/null ; then sudo apt install libnotify-bin -y > /dev/null 2>&1 ; echo libnotify wird installiert. Bitte warten... ; fi
elif grep -i 'arch\|manjaro\|garuda\|endeavour|' /etc/os-release > /dev/null 2>&1 elif grep -i 'arch\|manjaro\|garuda\|endeavour|' /etc/os-release > /dev/null 2>&1
then then
echo Wire-G wird installiert... echo Wire-G wird installiert...
mkdir -p /home/"$a_user"/.icons ; cp icons/* /home/"$a_user"/.icons/ ; mkdir -p /home/"$a_user"/.config/wg_nmcli mkdir -p /home/"$USER"/.icons ; cp icons/* /home/"$USER"/.icons/ ; mkdir -p /home/"$USER"/.config/wg_nmcli
if ! which yad > /dev/null ; then sudo pacman -S --noconfirm yad > /dev/null 2>&1 ; echo yad wird installiert. Bitte warten... ; fi if ! which yad > /dev/null ; then sudo pacman -S --noconfirm yad > /dev/null 2>&1 ; echo yad wird installiert. Bitte warten... ; fi
if ! which notify-send > /dev/null ; then sudo pacman -S --noconfirm libnotify > /dev/null 2>&1 ; echo libnotify wird installiert. Bitte warten... ; fi if ! which notify-send > /dev/null ; then sudo pacman -S --noconfirm libnotify > /dev/null 2>&1 ; echo libnotify wird installiert. Bitte warten... ; fi
elif grep -i 'fedora' /etc/os-release > /dev/null 2>&1 elif grep -i 'fedora' /etc/os-release > /dev/null 2>&1
then then
echo Wire-G wird installiert... echo Wire-G wird installiert...
mkdir -p /home/"$a_user"/.icons ; cp icons/* /home/"$a_user"/.icons/ ; mkdir -p /home/"$a_user"/.config/wg_nmcli mkdir -p /home/"$USER"/.icons ; cp icons/* /home/"$USER"/.icons/ ; mkdir -p /home/"$USER"/.config/wg_nmcli
if ! which yad > /dev/null ; then sudo dnf install yad > /dev/null 2>&1 ; echo yad wird installiert. Bitte warten... ; fi if ! which yad > /dev/null ; then sudo dnf install yad > /dev/null 2>&1 ; echo yad wird installiert. Bitte warten... ; fi
if ! which notify-send > /dev/null ; then sudo dnf install libnotify > /dev/null 2>&1 ; echo libnotify wird installiert. Bitte warten... ; fi if ! which notify-send > /dev/null ; then sudo dnf install libnotify > /dev/null 2>&1 ; echo libnotify wird installiert. Bitte warten... ; fi
@ -46,11 +44,11 @@ elif grep -i 'suse' /etc/os-release > /dev/null 2>&1
echo yad und libnotify müssen sie selbst installieren, wenn sie fortfahren! echo yad und libnotify müssen sie selbst installieren, wenn sie fortfahren!
echo da diese Pakete offiziell nicht verfügbar sind. echo da diese Pakete offiziell nicht verfügbar sind.
echo echo
read -p "Geben Sie i für die installation ein und die Eingabetaste, Abbruch mit jeder anderen Taste ..." response read -p "Geben Sie i für die installation ein und die Eingabetaste, Abbruch mit jeder anderen Taste ..." RESPONSE
if [ "$response" == "i" ] if [ "$RESPONSE" == "i" ]
then then
echo Wire-G wird installiert... echo Wire-G wird installiert...
mkdir -p /home/"$a_user"/.icons ; cp icons/* /home/"$a_user"/.icons/ ; mkdir -p /home/"$a_user"/.config/wg_nmcli mkdir -p /home/"$USER"/.icons ; cp icons/* /home/"$USER"/.icons/ ; mkdir -p /home/"$USER"/.config/wg_nmcli
else else
exit 1 exit 1
fi fi

View File

@ -10,11 +10,10 @@
######################################################## ########################################################
######################################################## ########################################################
a_user=$(whoami)
cd || exit cd || exit
rm -f /home/"$a_user"/.icons/wg-active.png wg-stop.png wg-vpn.png wg-import.png wg-trash.png wg-info.png rm -f /home/"$USER"/.icons/wg-active.png wg-stop.png wg-vpn.png wg-import.png wg-trash.png wg-info.png
wait; wait;
rm -r /home/"$a_user"/.config/wg_nmcli rm -r /home/"$USER"/.config/wg_nmcli
wait; wait;
sudo rm /usr/share/icons/Arch-Symbole/wg-vpn.png sudo rm /usr/share/icons/Arch-Symbole/wg-vpn.png
wait; wait;

27
wg_stop
View File

@ -14,28 +14,27 @@ Encoding=UTF-8
# i18n - Internationalization - Internationalisierung # i18n - Internationalization - Internationalisierung
export textdomain=wire-g export TEXTDOMAIN=wire-g
export textdomaindir="/usr/share/locale" export TEXTDOMAINDIR="/usr/share/locale"
############################################################################################################ ############################################################################################################
############################################################################################################ ############################################################################################################
a_user=$(whoami) WG_WDIR="/home/$USER/.config/wg_nmcli/"
wg_wdir="/home/$a_user/.config/wg_nmcli/" WG_PIC="/home/$USER/.icons/"
wg_pic="/home/$a_user/.icons/"
#Dieser befehl ist notwendig da nach dem import (erster Start) gestartete Tunnel nicht in der .tunnel Datei stehen. #Dieser befehl ist notwendig da nach dem import (erster Start) gestartete Tunnel nicht in der .tunnel Datei stehen.
nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' > ${wg_wdir}.tunnel.txt nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' > ${WG_WDIR}.tunnel.txt
#Damit wird der inhalt von /home/$a_user/.config/wg_nmcli/.tunnel.txt in ein Array gespeichert #Damit wird der inhalt von /home/$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) #echo ${lines[0]} #Damit wird der Inhalt ausgelesen. (Index angeben)
wert=$"*_*" VALUE=$"*_*"
for wert in "${lines[@]}" for VALUE in "${lines[@]}"
do do
# hier wird die Ausgabe von nmcli für die auswertung in die .stop.txt gespeichert # hier wird die Ausgabe von nmcli für die ausVALUEung in die .stop.txt gespeichert
nmcli connection down "$wert" &> ${wg_wdir}.stop.txt nmcli connection down "$VALUE" &> ${WG_WDIR}.stop.txt
if disable=$(grep -i 'deaktiviert\|deactivated' ${wg_wdir}.stop.txt) if disable=$(grep -i 'deaktiviert\|deactivated' ${WG_WDIR}.stop.txt)
then then
notify-send --icon=${wg_pic}wg-stop.png $"$wert Connection disconnected" notify-send --icon=${WG_PIC}wg-stop.png $"$VALUE Connection disconnected"
fi fi
done done
pkill yad pkill yad

156
wire_g
View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
######################################################## ########################################################
######################################################## ########################################################
# Wire-G App for simple management a Wireguard Tunnel ## # Wire-G App for simple management a Wireguard TUNNEL ##
# Author: Désiré Werner Menrath ## # Author: Désiré Werner Menrath ##
# Email: polunga40@unity-mail.de ## # Email: polunga40@unity-mail.de ##
# Translate German to English with LibreTranslate ## # Translate German to English with LibreTranslate ##
@ -19,46 +19,43 @@ export TEXTDOMAINDIR="/usr/share/locale"
############################################################################################################ ############################################################################################################
############################################################################################################ ############################################################################################################
version=3.1.3 VERSION=3.1.5
# Angemeldeten Benutzer ermitteln
a_user=$(whoami)
# wg_workdir Arbeitsverzeichnis wg # wg_workdir Arbeitsverzeichnis wg
wg_wdir="/home/$a_user/.config/wg_nmcli/" WG_WDIR="/home/$USER/.config/wg_nmcli/"
# Pfad wg Icons # Pfad wg Icons
wg_pic="/home/$a_user/.icons/" WG_PIC="/home/$USER/.icons/"
# Wireguard tunnel auslesen mit grep nur Wireguard zeigen # Wireguard TUNNEL auslesen mit grep nur Wireguard zeigen
# mit sed alles nach dem ersten Leerzeichen bis Zeilenende weggeschneiden und .tunnel.txt schreiben # 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 # Variable der verfügbaren TUNNELanzeige für Yad
tunnel=$(nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') TUNNEL=$(nmcli connection show | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
# Variable der aktiven Tunnelanzeige für Yad # Variable der aktiven TUNNELanzeige für Yad
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
############################################################################################################ ############################################################################################################
############################################################################################################ ############################################################################################################
wg_notify(){ wg_notify(){
a_user=$(whoami) ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') WG_PIC="/home/$USER/.icons/"
wg_pic="/home/$a_user/.icons/"
case $LANG in case $LANG in
de_DE.UTF-8) open=öffnen ;; de_DE.UTF-8) OPEN=öffnen ;;
*) open=open ;; *) OPEN=open ;;
esac esac
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 # 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
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 \
--text=$"$active activ" \ --text=$"$ACTIVE activ" \
--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"
} }
@ -70,35 +67,35 @@ export -f wg_notify
# funktion wireguard import # funktion wireguard import
import_wg(){ import_wg(){
a_user=$(whoami)
wg_pic="/home/$a_user/.icons/" WG_PIC="/home/$USER/.icons/"
wg_wdir="/home/$a_user/.config/wg_nmcli/" WG_WDIR="/home/$USER/.config/wg_nmcli/"
if wgconf=$(yad --file --separator=" \n" \ if WG_CONF=$(yad --file --separator=" \n" \
--button="OK" --button=$"Cancel" \ --button="OK" --button=$"Cancel" \
--width=1200 --height=800 --no-klick \ --width=1200 --height=800 --no-klick \
--window-icon=${wg_pic}wg-import.png \ --window-icon=${WG_PIC}wg-import.png \
--title=$"Wireguard .conf Select file") --title=$"Wireguard .conf Select file")
then then
case "$wgconf" in case "$WG_CONF" in
*_*.conf) if grep -i 'PEER\|PublicKey' $wgconf > /dev/null && grep -i 'Interface\|PrivateKey' $wgconf > /dev/null *_*.conf) if grep -i 'PEER\|PublicKey' $WG_CONF > /dev/null && grep -i 'Interface\|PrivateKey' $WG_CONF > /dev/null
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
wg_stop wg_stop
nmcli connection import type wireguard file $wgconf &> ${wg_wdir}.tmp.txt nmcli connection import type wireguard file $WG_CONF &> ${WG_WDIR}.tmp.txt
wg_notify wg_notify
else else
pkill yad pkill yad
nmcli connection import type wireguard file $wgconf &> ${wg_wdir}.tmp.txt nmcli connection import type wireguard file $WG_CONF &> ${WG_WDIR}.tmp.txt
wg_notify wg_notify
fi fi
fi ;; fi ;;
*) yad --button=$"OK" --title=$"Wireguard .conf Select file" \ *) yad --button=$"OK" --title=$"Wireguard .conf Select file" \
--window-icon=${wg_pic}wg-stop.png --image=${wg_pic}wg-info.png \ --window-icon=${WG_PIC}wg-stop.png --image=${WG_PIC}wg-info.png \
--center --buttons-layout=center --borders=8 --width=350 --height=60 \ --center --buttons-layout=center --borders=8 --width=350 --height=60 \
--text $"<b>Oh, something went wrong.</b> \n --text $"<b>Oh, something went wrong.</b> \n
<b>No valid Wireguard file.</b> \n <b>No valid Wireguard file.</b> \n
@ -115,26 +112,26 @@ export -f import_wg
remove(){ remove(){
nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//' &> ${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) ACTIVE=$(cat ${WG_WDIR}.wg_noactive.txt)
nmcli connection delete $selection &> ${wg_wdir}.tmp.txt nmcli connection delete $SELECTION &> ${WG_WDIR}.tmp.txt
if success=$(grep -i 'erfolgreich gelöscht\|successfully deleted' ${wg_wdir}.tmp.txt) if success=$(grep -i 'erfolgreich gelöscht\|successfully deleted' ${WG_WDIR}.tmp.txt)
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=$"Your tunnel $selection was successfully deleted." \ --text=$"Your TUNNEL $SELECTION was successfully deleted." \
--text-align=center --button=$"OK" --title "Wire-G Trash" \ --text-align=center --button=$"OK" --title "Wire-G Trash" \
--center --buttons-layout=center --borders=8 --center --buttons-layout=center --borders=8
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 something went wrong.\nPlease delete tunnel in the network manager." \ --text=$"Oh something went wrong.\nPlease delete TUNNEL in the network manager." \
--text-align=center --button=$"OK" --title "Wire-G Trash" \ --text-align=center --button=$"OK" --title "Wire-G Trash" \
--center --buttons-layout=center --borders=8 --center --buttons-layout=center --borders=8
fi fi
if [ "$selection" = "$active" ] if [ "$SELECTION" = "$ACTIVE" ]
then then
pkill yad pkill yad
fi } fi }
@ -143,18 +140,19 @@ remove(){
# function end # function end
############################################################################################################ ############################################################################################################
############################################################################################################ ############################################################################################################
#funktion for active tunnel a stop #funktion for active TUNNEL a stop
up_or_down(){ up_or_down(){
a_user=$(whoami)
wg_pic="/home/$a_user/.icons/" WG_PIC="/home/$USER/.icons/"
active=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//') ACTIVE=$(nmcli connection show --active | grep -iPo "(.*)(wireguard)" | sed 's/ .*//')
if [[ -z $active ]] if [[ -z $ACTIVE ]]
then 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." \ --text=$"\There is no active TUNNEL that you could stop." \
--text-align=center --button=$"OK" --title "Wire-G" \ --text-align=center --no-buttons --title "Wire-G" \
--center --buttons-layout=center --borders=8 --borders=8 --undecorated \
--timeout 4 --timeout-indicator=bottom --skip-taskbar
else else
wg_stop wg_stop
wire_g wire_g
@ -168,18 +166,18 @@ export -f up_or_down
# function button "more" # function button "more"
about(){ about(){
a_user=$(whoami)
wg_pic="/home/$a_user/.icons/" WG_PIC="/home/$USER/.icons/"
version=3.1.3 VERSION=3.1.5
yad --title="Wire-G" --center \ yad --title="Wire-G" --center \
--borders=8 --close-on-unfocus \ --borders=8 --buttons-layout=center --text-align=center \
--buttons-layout=center --text-align=center \ --button=$"OK" --undecorated \
--button=$"OK" --fixed \ --image-on-top --image=${WG_PIC}wg-vpn.png \
--separator="" --window-icon=${wg_pic}wg-vpn.png \ --separator="" --window-icon=${WG_PIC}wg-vpn.png \
--text=$"<span color='#626ff1'><b>Wire-G Author: Désiré Werner Menrath</b></span> \n --text=$"<span color='#626ff1'><b>Wire-G Author: Désiré Werner Menrath</b></span> \n
<span color='#626ff1'><b>E-Mail: polunga40@unity-mail.de</b></span> \n <span color='#626ff1'><b>E-Mail: polunga40@unity-mail.de</b></span> \n
<span color='#626ff1'><b>At all tunnels, the auto start is disabled.</b></span> \n <span color='#626ff1'><b>At all Tunnels, the auto start is disabled.</b></span> \n
<span color='#626ff1'><b>Version: $version </b></span> \n <span color='#626ff1'><b>Version: $VERSION </b></span> \n
<span color='#626ff1'><b>Use without warranty.</b></span> \n <span color='#626ff1'><b>Use without warranty.</b></span> \n
<a href='https://git.lunix.dedyn.io/punix/Wire-G'>Download Wire-G </a> \n" <a href='https://git.lunix.dedyn.io/punix/Wire-G'>Download Wire-G </a> \n"
@ -193,33 +191,33 @@ export -f about
connect(){ connect(){
if success=$(grep -i 'erfolgreich aktiviert\|successfully activated' ${wg_wdir}.tmp.txt) if SUCCESS=$(grep -i 'erfolgreich aktiviert\|successfully activated' ${WG_WDIR}.tmp.txt)
then then
pkill yad pkill yad
nmcli con mod $selection connection.autoconnect no nmcli con mod $SELECTION connection.autoconnect no
wg_notify wg_notify
fi } fi }
# function end # function end
############################################################################################################ ############################################################################################################
############################################################################################################ # --text "<b>Aktiver Tunnel:</b> <span color='#0fad0a'><b>$active</b></span> # mit <b>gewünschtes wort</b> wird fett geschrieben. ############################################################################################################ # --text "<b>Aktiver TUNNEL:</b> <span color='#0fad0a'><b>$ACTIVE</b></span> # mit <b>gewünschtes wort</b> wird fett geschrieben.
# Farbe für Variable $active festgelegt mit fetter Schrift. (bei --text zwischen " ") # Farbe für Variable $ACTIVE festgelegt mit fetter Schrift. (bei --text zwischen " ")
selection=$(yad --no-klick --list --center \ SELECTION=$(yad --no-klick --list --center \
--height=300 --width=60 --title="Wire-G" \ --height=300 --width=60 --title="Wire-G" \
--buttons-layout=center \ --buttons-layout=center \
--button=$"Start:0" --button=$"Stop":"bash -c up_or_down" \ --button=$"Start:0" --button=$"Stop":"bash -c up_or_down" \
--button=$"Import":"bash -c import_wg" \ --button=$"Import":"bash -c import_wg" \
--button=$"Remove:4" --separator="" \ --button=$"Remove:4" --separator="" \
--button=$"About":"bash -c about" \ --button=$"About":"bash -c about" \
--window-icon=${wg_pic}wg-vpn.png \ --window-icon=${WG_PIC}wg-vpn.png \
--borders=8 --image-on-top --image=${wg_pic}wg-active.png \ --borders=8 --image-on-top --image=${WG_PIC}wg-active.png \
--column=$"Selection" $tunnel \ --column=$"Selection" $TUNNEL \
--text=$"<b>Activ Tunnel: </b> <span color='#0fad0a'><b>$active</b></span> --text=$"<b>Activ Tunnel: </b> <span color='#0fad0a'><b>$ACTIVE</b></span>
<b>----------------------------------------------------------------------------------</b> <b>----------------------------------------------------------------------------------</b>
<b>If no tunnels are listed,</b> <b>If no Tunnels are listed,</b>
<b>so they have to import their tunnel beforehand.</b>") <b>so they have to import their Tunnel beforehand.</b>")
ret=$? ret=$?
[[ $? -eq 1 ]] && exit 0 [[ $? -eq 1 ]] && exit 0
@ -231,19 +229,17 @@ fi
if [[ $ret -eq 0 ]] if [[ $ret -eq 0 ]]
then then
if [[ -n $active ]] if [[ -n $ACTIVE ]]
then then
wg_stop wg_stop
nmcli connection up $selection &> ${wg_wdir}.tmp.txt nmcli connection up $SELECTION &> ${WG_WDIR}.tmp.txt
connect connect
else else
nmcli connection up $selection &> ${wg_wdir}.tmp.txt nmcli connection up $SELECTION &> ${WG_WDIR}.tmp.txt
connect connect
fi fi
fi fi
############################################ END ########################################################## ############################################ END ##########################################################