#!/bin/bash PIPE=$(mktemp -u --tmpdir ssh_tray.XXXXXX) mkfifo "$PIPE" to_pipe() { echo "$1" > "$PIPE" & } LAST_LOGICAL_STATE="" update_tray() { CURRENT_STATUS=$(systemctl is-active sshtunnel.service) 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 to_pipe "icon:network-transmit" to_pipe "tooltip:SSH Tunel: BĚŽÍ" else to_pipe "icon:network-offline" to_pipe "tooltip:SSH Tunel: VYPNUTO" fi LAST_LOGICAL_STATE="$LOGICAL_STATE" } toggle_service() { if systemctl is-active --quiet sshtunnel.service; then systemctl stop sshtunnel.service else systemctl start sshtunnel.service fi update_tray } quit_tray() { systemctl stop sshtunnel.service echo "quit" > "$PIPE" rm -f "$PIPE" exit 0 } export -f toggle_service export -f update_tray export -f to_pipe export -f quit_tray export PIPE exec 3<> "$PIPE" systemctl start sshtunnel.service NO_AT_BRIDGE=1 yad --notification --kill-parent --listen \ --image=network-offline \ --text="SSH 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