From f9f5d74144b11ebb6df156549365453ea426e379 Mon Sep 17 00:00:00 2001
From: Helmut Grohne <helmut@subdivi.de>
Date: Thu, 22 Jun 2023 22:30:30 +0200
Subject: debvm-run: restore behaviour of repeated --sshport flags

When issuing multiple --sshport options, the last one should win.

Fixes: a2db07766257 ("debvm-run: add a --netopt option to customize the -netdev")
---
 bin/debvm-run | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/bin/debvm-run b/bin/debvm-run
index a4a0890..1019ac7 100755
--- a/bin/debvm-run
+++ b/bin/debvm-run
@@ -113,6 +113,7 @@ IMAGE=rootfs.ext4
 GRAPHICAL=
 CMDLINE_APPEND=
 NETOPTS=
+SSHPORT=
 
 nth_arg() {
 	shift "$1"
@@ -152,7 +153,7 @@ opt_netopt() {
 	NETOPTS="$NETOPTS,$1"
 }
 opt_sshport() {
-	opt_netopt "hostfwd=tcp:127.0.0.1:$1-:22"
+	SSHPORT=$1
 }
 
 while getopts :gi:s:-: OPTCHAR; do
@@ -194,6 +195,10 @@ while getopts :gi:s:-: OPTCHAR; do
 done
 shift "$((OPTIND - 1))"
 
+if test -n "$SSHPORT"; then
+	opt_netopt "hostfwd=tcp:127.0.0.1:$SSHPORT-:22"
+fi
+
 test -f "$IMAGE" || die "image '$IMAGE' not found"
 test -s "$IMAGE" || die "image '$IMAGE' is empty"
 
-- 
cgit v1.2.3