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

View file

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