vncsconnect : ré-écriture
This commit is contained in:
parent
0b06da983d
commit
e109b58d68
1 changed files with 11 additions and 37 deletions
|
@ -1,40 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
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"
|
||||
|
||||
# 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
|
||||
#!/usr/bin/env sh
|
||||
if [ -z "$1" ]; then
|
||||
>&2 echo "provide ssh host name"
|
||||
exit 1
|
||||
else
|
||||
vncviewer=vncviewer
|
||||
separator=:
|
||||
ssh_host=$1
|
||||
fi
|
||||
remote_port=${2:-5900}
|
||||
local_port=$((remote_port + 4000))
|
||||
|
||||
# Initialiser les arguments du viewer
|
||||
args=(localhost "$local_port")
|
||||
if [ -n "$separator" ]; then
|
||||
args=("${args[*]// /${separator}/}")
|
||||
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[@]}"
|
||||
ssh -O check -- "$ssh_host"
|
||||
ssh -f -N -L "${local_port}:localhost:${remote_port}" -- "$ssh_host" || exit
|
||||
wlvncc -- localhost "$local_port"
|
||||
ssh -O cancel -L "${local_port}:localhost:${remote_port}" -- "$ssh_host"
|
||||
|
|
Loading…
Reference in a new issue