2023-04-13 00:04:20 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Variables
|
2023-06-17 19:38:33 +02:00
|
|
|
declare -a ssh_args
|
2023-04-13 00:04:20 +02:00
|
|
|
|
2023-06-17 19:52:19 +02:00
|
|
|
# Fonction
|
|
|
|
ssh_bridge_already_exists() {
|
|
|
|
[ -n "$(lsof -nP -i TCP -s TCP:LISTEN | awk '($1 == "ssh" && $9 ~ /.*:'"${1}"'/) { print }')" ]
|
|
|
|
}
|
|
|
|
|
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
|
|
|
# Arguments
|
|
|
|
while [ -n "$1" ]; do
|
|
|
|
case "$1" in
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ssh_args+=("$1")
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2023-04-13 00:04:20 +02:00
|
|
|
|
2023-06-17 19:38:33 +02:00
|
|
|
# Initialiser les arguments du viewer
|
|
|
|
args=(localhost "${ssh_args[1]}")
|
|
|
|
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-10-19 18:44:28 +02:00
|
|
|
if ! ssh_bridge_already_exists "${ssh_args[1]}"; then
|
2023-11-11 18:07:23 +01:00
|
|
|
ssh-fwd "${ssh_args[@]}" || 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[@]}"
|