1
0
Fork 0
forked from ahurac/dotfiles
ahuarc-dotfiles/bin/vncsconnect
2023-11-11 18:07:23 +01:00

46 lines
874 B
Bash
Executable file

#!/bin/bash
# Variables
declare -a ssh_args
# Fonction
ssh_bridge_already_exists() {
[ -n "$(lsof -nP -i TCP -s TCP:LISTEN | awk '($1 == "ssh" && $9 ~ /.*:'"${1}"'/) { print }')" ]
}
# Sélectionner le viewer adapté à la session
if [ -n "$WAYLAND_DISPLAY" ]; then
vncviewer=wlvncc
else
vncviewer=vncviewer
separator=:
fi
# Arguments
while [ -n "$1" ]; do
case "$1" in
--)
shift
break
;;
*)
ssh_args+=("$1")
shift
;;
esac
done
# Initialiser les arguments du viewer
args=(localhost "${ssh_args[1]}")
if [ -n "$separator" ]; then
args=("${args[*]// /${separator}/}")
fi
# Exécution
if ! ssh_bridge_already_exists "${ssh_args[1]}"; then
ssh-fwd "${ssh_args[@]}" || exit
else
echo "Le pont SSH existe déjà !"
fi
exec "$vncviewer" "${args[@]}"