Correction : réécriture de vncsconnect. ssh-fwd { Correction : shift avant de break dans l'analyse d'arguments ; arguments à la fin pour pouvoir exécuter des commandes

This commit is contained in:
Hippolyte Chauvin 2023-06-17 19:38:33 +02:00
parent 067d6f722d
commit ba4afebe09
2 changed files with 34 additions and 31 deletions

View file

@ -38,6 +38,7 @@ requested_port_bridge_pid() {
while [ -n "$1" ]; do
case "$1" in
--)
shift
break
;;
*)
@ -55,11 +56,11 @@ fi
pid="$(requested_port_bridge_pid "${args[1]}")"
if [ -z "$pid" ]; then
exec "${ssh[@]}" \
"$@" \
-f \
-N \
-L "${args[1]}:${args[3]:-localhost}:${args[2]}" \
"${args[0]}"
"${args[0]}" \
"$@"
else
echo "Suppression de la redirection..."
kill "$pid"

View file

@ -1,37 +1,39 @@
#!/bin/bash
# Variables
declare -a make_ssh_bridge open_vnc_session
ssh_fwd=ssh-fwd
vncviewer=wlvncc
localhost=localhost
declare -a ssh_args
# Sélectionner le viewer adapté à la session
if [ -n "$WAYLAND_DISPLAY" ]; then
vncviewer=wlvncc
else
vncviewer=vncviewer
separator=:
fi
# Arguments
ssh_host="$1" ; shift
local_port="${1:-9900}" ; shift
distant_port="${1:-5900}"; shift
target="$1" ; shift
while [ -n "$1" ]; do
case "$1" in
--)
shift
break
;;
*)
ssh_args+=("$1")
shift
;;
esac
done
# Commands building
# Make SSH bridge
make_ssh_bridge+=(
"$ssh_fwd"
"$ssh_host"
"$local_port"
"$distant_port"
"$target"
)
# Initialiser les arguments du viewer
args=(localhost "${ssh_args[1]}")
if [ -n "$separator" ]; then
args=("${args[*]// /${separator}/}")
fi
# Open VNC session
open_vnc_session+=(
"$vncviewer"
"$@"
"${localhost}"
"${local_port}"
)
# Execution
set -xe
"${make_ssh_bridge[@]}"
"${open_vnc_session[@]}"
# Exécution
set -e
ssh-fwd "${ssh_args[@]}" -- "$@"
exec "$vncviewer" \
"${args[@]}"