2023-04-13 00:04:20 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2023-11-11 18:43:05 +01:00
|
|
|
vnc_host="$1"
|
|
|
|
if [ -n "$2" ]
|
|
|
|
then local_port="$2"
|
|
|
|
else local_port=9900
|
|
|
|
fi
|
|
|
|
if [ -n "$3" ]
|
|
|
|
then distant_port="$3"
|
|
|
|
else distant_port=5900
|
|
|
|
fi
|
|
|
|
[ -n "$4" ] && ssh_target="$4"
|
2023-04-13 00:04:20 +02:00
|
|
|
|
2023-06-17 19:52:19 +02:00
|
|
|
# Fonction
|
|
|
|
ssh_bridge_already_exists() {
|
2023-11-11 18:43:05 +01:00
|
|
|
[ -n "$(lsof -nP -i TCP -s TCP:LISTEN | awk '($1 == "ssh" && $9 ~ /.*:'"${local_port}"'/) { print }')" ]
|
2023-06-17 19:52:19 +02:00
|
|
|
}
|
|
|
|
|
2023-06-17 19:38:33 +02:00
|
|
|
# Sélectionner le viewer adapté à la session
|
|
|
|
if [ -n "$WAYLAND_DISPLAY" ]; then
|
|
|
|
vncviewer=wlvncc
|
|
|
|
else
|
|
|
|
vncviewer=vncviewer
|
|
|
|
separator=:
|
|
|
|
fi
|
2023-04-13 00:04:20 +02:00
|
|
|
|
2023-06-17 19:38:33 +02:00
|
|
|
# Initialiser les arguments du viewer
|
2023-11-11 18:43:05 +01:00
|
|
|
args=(localhost "$local_port")
|
2023-06-17 19:38:33 +02:00
|
|
|
if [ -n "$separator" ]; then
|
|
|
|
args=("${args[*]// /${separator}/}")
|
|
|
|
fi
|
2023-04-13 00:04:20 +02:00
|
|
|
|
2023-06-17 19:38:33 +02:00
|
|
|
# Exécution
|
2023-11-11 18:43:05 +01:00
|
|
|
if ! ssh_bridge_already_exists; then
|
|
|
|
ssh-fwd "$vnc_host" "$local_port" "$distant_port" "$ssh_target" || exit
|
2023-06-17 19:52:19 +02:00
|
|
|
else
|
|
|
|
echo "Le pont SSH existe déjà !"
|
|
|
|
fi
|
2023-04-13 00:04:20 +02:00
|
|
|
|
2023-11-11 18:07:23 +01:00
|
|
|
exec "$vncviewer" "${args[@]}"
|