#!/bin/bash PIPE=$(mktemp -u --tmpdir ssh_tray.XXXXXX) mkfifo "$PIPE" VNC_PID="" to_pipe() { echo "$1" > "$PIPE" & } stop_vnc() { pkill -u "ris" -f "x11vnc.*-listen 10.252." sudo systemctl stop sshd-wg0 } LAST_LOGICAL_STATE="" update_tray() { CURRENT_STATUS=$(systemctl is-active wg-quick@wg0) if [ "$CURRENT_STATUS" == "active" ]; then LOGICAL_STATE="on" else LOGICAL_STATE="off" fi if [ "$LOGICAL_STATE" == "$LAST_LOGICAL_STATE" ]; then return fi if [ "$LOGICAL_STATE" == "on" ]; then WG0_IP=$(ifconfig wg0 2>/dev/null | grep -Po 'inet \K[\d.]+') if [ -n "$WG0_IP" ] && ! pgrep --quiet -u "ris" -f "x11vnc.*-listen 10.252."; then x11vnc -no6 -wait 50 -noxdamage -display :0 -forever -bg -nopw -listen "$WG0_IP" -rfbport 5910 & sudo systemctl start sshd-wg0 fi to_pipe "icon:network-transmit" to_pipe "tooltip:WireGuard Tunel: BĚŽÍ $WG0_IP" else stop_vnc to_pipe "icon:network-offline" to_pipe "tooltip:WireGuard Tunel: VYPNUTO" fi LAST_LOGICAL_STATE="$LOGICAL_STATE" } toggle_service() { if systemctl is-active --quiet wg-quick@wg0; then sudo systemctl stop wg-quick@wg0 else sudo systemctl start wg-quick@wg0 fi update_tray } quit_tray() { stop_vnc sudo systemctl stop wg-quick@wg0 echo "quit" > "$PIPE" rm -f "$PIPE" exit 0 } export -f stop_vnc export -f toggle_service export -f update_tray export -f to_pipe export -f quit_tray export PIPE exec 3<> "$PIPE" sudo systemctl start wg-quick@wg0 NO_AT_BRIDGE=1 yad --notification --kill-parent --listen \ --image=network-offline \ --text="WireGuard Tunel" \ --command="bash -c toggle_service" \ --menu="Ukončit vzdálenou podporu!bash -c quit_tray" <&3 & while true; do update_tray sleep 5 done