scripts/network/start_vnc/start_vnc.sh

26 lines
1.1 KiB
Bash
Raw Normal View History

2023-12-28 10:02:44 +01:00
#!/bin/bash
USERNAME=${USER,,}
LOCK_FILE=/tmp/start_vnc_$USERNAME.lock
ICON=application-x-vnc
SSH_HOST=ulrich.earth
SSH_PORT=2222
SSH_USER=karin
(
flock -n 200 || { echo "already running, exiting."; exit 1; }
gsettings set org.gnome.desktop.remote-desktop.vnc auth-method 'password'
gsettings set org.gnome.desktop.remote-desktop.vnc view-only false
gsettings set org.gnome.desktop.remote-desktop.vnc enable true
password=$(echo -e $(od -vAn -N3 -tu4 < /dev/urandom))
info_text="Bildschirmfreigabe aktiv! Passwort: $password"
echo -n "$password" | secret-tool store --label="GNOME Remote Desktop VNC password" "xdg:schema" "org.gnome.RemoteDesktop.VncPassword"
systemctl --user start gnome-remote-desktop.service
ssh -C -N -R 5900:localhost:5900 -p $SSH_PORT $SSH_USER@$SSH_HOST &
ssh_pid="$!"
zenity --title="Bildschirmfreigabe auf $(hostname)" --info --text="$info_text" --width=230 --ok-label="Beenden" --icon-name="$ICON"
kill $ssh_pid
systemctl --user stop gnome-remote-desktop.service
gsettings set org.gnome.desktop.remote-desktop.vnc enable false
) 200>"$LOCK_FILE"