vncsconnect : ré-écriture

This commit is contained in:
Ahurac 2024-04-22 00:53:46 +02:00
parent 0b06da983d
commit e109b58d68

View file

@ -1,40 +1,14 @@
#!/bin/bash #!/usr/bin/env sh
if [ -z "$1" ]; then
vnc_host="$1" >&2 echo "provide ssh host name"
if [ -n "$2" ] exit 1
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"
# Fonction
ssh_bridge_already_exists() {
[ -n "$(lsof -nP -i TCP -s TCP:LISTEN | awk '($1 == "ssh" && $9 ~ /.*:'"${local_port}"'/) { print }')" ]
}
# Sélectionner le viewer adapté à la session
if [ -n "$WAYLAND_DISPLAY" ]; then
vncviewer=wlvncc
else else
vncviewer=vncviewer ssh_host=$1
separator=:
fi fi
remote_port=${2:-5900}
local_port=$((remote_port + 4000))
# Initialiser les arguments du viewer ssh -O check -- "$ssh_host"
args=(localhost "$local_port") ssh -f -N -L "${local_port}:localhost:${remote_port}" -- "$ssh_host" || exit
if [ -n "$separator" ]; then wlvncc -- localhost "$local_port"
args=("${args[*]// /${separator}/}") ssh -O cancel -L "${local_port}:localhost:${remote_port}" -- "$ssh_host"
fi
# Exécution
if ! ssh_bridge_already_exists; then
ssh-fwd "$vnc_host" "$local_port" "$distant_port" "$ssh_target" || exit
else
echo "Le pont SSH existe déjà !"
fi
exec "$vncviewer" "${args[@]}"