From 130f3bbf71a9ce28925dd27c05b6887870fb3a0f Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 3 Jan 2023 12:04:00 +0100 Subject: add a debvm-waitssh utility --- debvm-waitssh | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/create-and-run.sh | 2 +- tests/dist-upgrades.sh | 4 +-- tests/test_common.sh | 11 ------- 4 files changed, 79 insertions(+), 14 deletions(-) create mode 100755 debvm-waitssh diff --git a/debvm-waitssh b/debvm-waitssh new file mode 100755 index 0000000..092b46f --- /dev/null +++ b/debvm-waitssh @@ -0,0 +1,76 @@ +#!/bin/sh +# Copyright 2023 Helmut Grohne +# SPDX-License-Identifier: MIT + +: <<'POD2MAN' +=head1 NAME + +debvm-waitssh - Wait for a ssh server to be reachable + +=head1 SYNOPSIS + +B [I:]I + +=head1 DESCRIPTION + +B can be used to wait for a virtual machine with exposed ssh port to be reachable on that port. +If no hostname is given, B is assumed. + +=head1 EXIT VALUES + +=over 8 + +=item B<0> + +The server is reachable. + +=item B<1> + +A timeout was reached before the server answered. + +=item B<2> + +Usage error. + +=back + +=head1 SEE ALSO + + debvm-run(1) + +=cut +POD2MAN + +set -u + +case "${1:-}" in + "") + echo "usage: $0 " >&2 + exit 2 + ;; + *:*) + HOST=${1%:*} + PORT=${1##*:} + ;; + *) + HOST=localhost + PORT=$1 + ;; +esac + +TOTALTIMEOUT=60 +SCANTIMEOUT=10 +SCANDELAY=1 +now=$(date +%s) +deadline=$((now + TOTALTIMEOUT)) +while test "$now" -lt "$deadline"; do + start=$now + ssh-keyscan -T "$SCANTIMEOUT" -p "$PORT" "$HOST" >/dev/null 2>&1 && exit 0 + now=$(date +%s) + if test "$((now - start))" -lt "$SCANTIMEOUT"; then + sleep "$SCANDELAY" + now=$(date +%s) + fi +done +exit 1 + diff --git a/tests/create-and-run.sh b/tests/create-and-run.sh index 540e6c4..4ec07eb 100755 --- a/tests/create-and-run.sh +++ b/tests/create-and-run.sh @@ -26,6 +26,6 @@ SSH_PORT=2222 timeout 240s debvm-run -s "$SSH_PORT" -i "$IMAGE" & set -- localhost test "$RELEASE" = jessie && set -- -o PubkeyAcceptedKeyTypes=+ssh-rsa "$@" -wait_ssh "$@" +debvm-waitssh "$SSH_PORT" run_ssh "$@" poweroff wait diff --git a/tests/dist-upgrades.sh b/tests/dist-upgrades.sh index 85c9f4a..3bab4ab 100755 --- a/tests/dist-upgrades.sh +++ b/tests/dist-upgrades.sh @@ -44,12 +44,12 @@ for RELEASE in stretch buster bullseye bookworm sid; do timeout 15m debvm-run -s "$SSH_PORT" & set -- localhost test "$RELEASE" = stretch && set -- -o PubkeyAcceptedKeyTypes=+ssh-rsa "$@" - wait_ssh "$@" + debvm-waitssh "$SSH_PORT" run_ssh "$@" "upgrade $RELEASE" wait done timeout 5m debvm-run -s "$SSH_PORT" & -wait_ssh localhost +debvm-waitssh "$SSH_PORT" run_ssh localhost poweroff wait diff --git a/tests/test_common.sh b/tests/test_common.sh index f42a26a..cba9693 100644 --- a/tests/test_common.sh +++ b/tests/test_common.sh @@ -5,14 +5,3 @@ run_ssh() { test -n "${SSH_PORT:-}" && set -- -p "$SSH_PORT" "$@" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -l root "$@" } - -wait_ssh() { - wait_ssh_timeout=5 - wait_ssh_ts=$(sleepenh 0 || [ $? -eq 1 ]) - for _ in $(seq 30); do - run_ssh -o ConnectTimeout="$wait_ssh_timeout" "$@" echo success && return 0 - wait_ssh_ts=$(sleepenh "$wait_ssh_ts" "$wait_ssh_timeout" || [ $? -eq 1 ]) - done - echo "timeout reached" >&2 - return 1 -} -- cgit v1.2.3 From 0234911df5000ef720829c1002687e6e90badaf3 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 3 Jan 2023 12:13:09 +0100 Subject: gitlab-ci: stop installing sleepenh --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d2a1bbf..456e8d9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,7 +27,7 @@ release_test: script: - apt-get update - apt-get dist-upgrade --yes - - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client sleepenh qemu-kvm + - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client qemu-kvm - PATH=.:$PATH ./tests/create-and-run.sh $(dpkg --print-architecture) "$RELEASE" arch_test: @@ -45,5 +45,5 @@ arch_test: - test -e /proc/sys/fs/binfmt_misc/status || mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc - apt-get update - apt-get dist-upgrade --yes - - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client sleepenh qemu-system binfmt-support arch-test qemu-user-static + - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client qemu-system binfmt-support arch-test qemu-user-static - PATH=.:$PATH ./tests/create-and-run.sh "$ARCHITECTURE" sid -- cgit v1.2.3 From 4e959cc83446ab426649425add520d3da58bfdd3 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 3 Jan 2023 13:08:57 +0100 Subject: debvm-waitssh: make timeout configurable and restore previous value for tests --- debvm-waitssh | 84 ++++++++++++++++++++++++++++++++++++++++++++----- tests/create-and-run.sh | 2 +- tests/dist-upgrades.sh | 4 +-- 3 files changed, 79 insertions(+), 11 deletions(-) diff --git a/debvm-waitssh b/debvm-waitssh index 092b46f..843963d 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -9,13 +9,24 @@ debvm-waitssh - Wait for a ssh server to be reachable =head1 SYNOPSIS -B [I:]I +B [B<-t> I] [I:]I =head1 DESCRIPTION B can be used to wait for a virtual machine with exposed ssh port to be reachable on that port. If no hostname is given, B is assumed. +=head1 OPTIONS + +=over 8 + +=item B<-t> I, B<--timeout>=I + +Set the maximum duration for waiting in seconds. +Defaults to one minute. + +=back + =head1 EXIT VALUES =over 8 @@ -43,10 +54,70 @@ POD2MAN set -u -case "${1:-}" in +TOTALTIMEOUT=60 +SCANTIMEOUT=10 +SCANDELAY=1 + +nth_arg() { + shift "$1" + printf "%s" "$1" +} + +die() { + echo "$*" >&2 + exit 2 +} +usage() { + die "usage: $0 [-t ] [:]" +} +usage_error() { + echo "error: $*" >&2 + usage +} + +opt_timeout() { + TOTALTIMEOUT=$1 +} + +while getopts :t:-: OPTCHAR; do + case "$OPTCHAR" in + t) opt_timeout "$OPTARG" ;; + -) + case "$OPTARG" in + help) + usage + ;; + timeout) + test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG" + "opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")" + OPTIND=$((OPTIND+1)) + ;; + timeout=) + "opt_${OPTARG%%=*}" "${OPTARG#*=}" + ;; + *) + usage_error "unrecognized option --$OPTARG" + ;; + esac + ;; + :) + usage_error "missing argument for -$OPTARG" + ;; + '?') + usage_error "unrecognized option -$OPTARG" + ;; + *) + die "internal error while parsing command options, please report a bug" + ;; + esac +done +shift "$((OPTIND - 1))" + +test "$#" = 1 || usage + +case "$1" in "") - echo "usage: $0 " >&2 - exit 2 + usage ;; *:*) HOST=${1%:*} @@ -58,9 +129,6 @@ case "${1:-}" in ;; esac -TOTALTIMEOUT=60 -SCANTIMEOUT=10 -SCANDELAY=1 now=$(date +%s) deadline=$((now + TOTALTIMEOUT)) while test "$now" -lt "$deadline"; do @@ -68,7 +136,7 @@ while test "$now" -lt "$deadline"; do ssh-keyscan -T "$SCANTIMEOUT" -p "$PORT" "$HOST" >/dev/null 2>&1 && exit 0 now=$(date +%s) if test "$((now - start))" -lt "$SCANTIMEOUT"; then - sleep "$SCANDELAY" + sleep "$SCANDELAY" now=$(date +%s) fi done diff --git a/tests/create-and-run.sh b/tests/create-and-run.sh index 4ec07eb..f978052 100755 --- a/tests/create-and-run.sh +++ b/tests/create-and-run.sh @@ -26,6 +26,6 @@ SSH_PORT=2222 timeout 240s debvm-run -s "$SSH_PORT" -i "$IMAGE" & set -- localhost test "$RELEASE" = jessie && set -- -o PubkeyAcceptedKeyTypes=+ssh-rsa "$@" -debvm-waitssh "$SSH_PORT" +debvm-waitssh -t 150 "$SSH_PORT" run_ssh "$@" poweroff wait diff --git a/tests/dist-upgrades.sh b/tests/dist-upgrades.sh index 3bab4ab..177712b 100755 --- a/tests/dist-upgrades.sh +++ b/tests/dist-upgrades.sh @@ -44,12 +44,12 @@ for RELEASE in stretch buster bullseye bookworm sid; do timeout 15m debvm-run -s "$SSH_PORT" & set -- localhost test "$RELEASE" = stretch && set -- -o PubkeyAcceptedKeyTypes=+ssh-rsa "$@" - debvm-waitssh "$SSH_PORT" + debvm-waitssh -t 150 "$SSH_PORT" run_ssh "$@" "upgrade $RELEASE" wait done timeout 5m debvm-run -s "$SSH_PORT" & -debvm-waitssh "$SSH_PORT" +debvm-waitssh -t 150 "$SSH_PORT" run_ssh localhost poweroff wait -- cgit v1.2.3 From 354f9790fb3706a229b9eb4b1d02d578d4297bdc Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 3 Jan 2023 16:56:38 +0100 Subject: debvm-waitssh: force ipv4 On salsa, localhost resolves to ::1 and ssh-keyscan skips checking 127.0.0.1 there. --- debvm-waitssh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debvm-waitssh b/debvm-waitssh index 843963d..557ffad 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -14,7 +14,7 @@ B [B<-t> I] [I:]I =head1 DESCRIPTION B can be used to wait for a virtual machine with exposed ssh port to be reachable on that port. -If no hostname is given, B is assumed. +If no hostname is given, B<127.0.0.1> is assumed. =head1 OPTIONS @@ -124,7 +124,7 @@ case "$1" in PORT=${1##*:} ;; *) - HOST=localhost + HOST=127.0.0.1 PORT=$1 ;; esac -- cgit v1.2.3 From 472bc82b69e2785f0fb715efbb796bdd9f5507c0 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 3 Jan 2023 16:58:30 +0100 Subject: debvm-waitssh: issue fewer test connections ssh-keyscan creates one connection per key type. --- debvm-waitssh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debvm-waitssh b/debvm-waitssh index 557ffad..4d69657 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -133,7 +133,7 @@ now=$(date +%s) deadline=$((now + TOTALTIMEOUT)) while test "$now" -lt "$deadline"; do start=$now - ssh-keyscan -T "$SCANTIMEOUT" -p "$PORT" "$HOST" >/dev/null 2>&1 && exit 0 + ssh-keyscan -t rsa -T "$SCANTIMEOUT" -p "$PORT" "$HOST" >/dev/null 2>&1 && exit 0 now=$(date +%s) if test "$((now - start))" -lt "$SCANTIMEOUT"; then sleep "$SCANDELAY" -- cgit v1.2.3 From ebf8917c9791659df8c995993484a21be922f2e1 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sat, 7 Jan 2023 16:22:28 +0100 Subject: debvm-run: add an example (I always forget about the -snapshot option) --- debvm-run | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/debvm-run b/debvm-run index 9b64ef4..eda3477 100755 --- a/debvm-run +++ b/debvm-run @@ -49,6 +49,15 @@ One possible use of this method is passing B<-snapshot> to avoid modifying the v =back +=head1 EXAMPLES + +Run a virtual machine stored in the image B (the default) with +local port 8022 routed to port 22 of the virtual machine. The B<-snapshot> +argument is passed to QEMU and prevents any permanent changes to +B, resulting in an ephemeral run. + + debvm-run -s 8022 -i rootfs.ext4 -- -snapshot + =head1 LIMITATIONS Due to the way kernel and bootloader are being extracted before running B, one cannot upgrade a kernel and then just reboot. -- cgit v1.2.3 From fcc6be9ec9d98321c7c987d9d8277c149f2bc1f4 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sat, 7 Jan 2023 21:38:35 +0100 Subject: use more perlpod formatting codes --- debvm-create | 10 +++++----- debvm-run | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/debvm-create b/debvm-create index 58094cc..c6f4b5c 100755 --- a/debvm-create +++ b/debvm-create @@ -11,7 +11,7 @@ debvm-create - Create a VM image for various Debian releases and architectures =head1 SYNOPSIS -B [B<-a> I] [B<-h> I] [B<-k> I] [B<-m> I] [B<-o> I] [B<-p> I] [B<-r> I] [B<-z> I] [B<--> I] +B [B<-a> I] [B<-h> I] [B<-k> F] [B<-m> I] [B<-o> F] [B<-p> I] [B<-r> I] [B<-z> I] [B<--> I] =head1 DESCRIPTION @@ -37,7 +37,7 @@ A suitable kernel image is automatically selected and installed into the image. Set the hostname of the virtual machine. By default, the hostname is B. -=item B<-k> I, B<--sshkey>=I +=item B<-k> F, B<--sshkey>=F Install the given ssh public key file into the virtual machine image for the root user. This option also causes the ssh server to be installed. @@ -47,12 +47,12 @@ To connect to the vm, pass a port number to B with the B<-s> option. =item B<-m> I, B<--mirror>=I Specify the Debian mirror to be used for downloading packages and to be configured inside the virtual machine image. -By default, B is being used. +By default, L is being used. -=item B<-o> I, B<--output>=I +=item B<-o> F, B<--output>=F Specify the file name of the resulting virtual machine image. -By default, it is written to B. +By default, it is written to F. =item B<-p> I, B<--package>=I diff --git a/debvm-run b/debvm-run index eda3477..c2a3f21 100755 --- a/debvm-run +++ b/debvm-run @@ -9,14 +9,14 @@ debvm-run - Run a VM image created by debvm-create =head1 SYNOPSIS -B [B<-g>] [B<-i> I] [B<-s> I] [B<--> I] +B [B<-g>] [B<-i> F] [B<-s> I] [B<--> I] =head1 DESCRIPTION B is essentially a thin wrapper around B for running a virtual machine image created by B or something compatible. The virtual machine image is expected to be a raw ext4 image with file system label B. -The architecture of the machine is detected from the contained B. -It must contain a symbolic link pointing to a kernel image at B or B depending on the architecture and a symbolic link pointing to an initrd image at B. +The architecture of the machine is detected from the contained F. +It must contain a symbolic link pointing to a kernel image at F or F depending on the architecture and a symbolic link pointing to an initrd image at F. Both are extracted and passed to B. A net interface configured for user mode is added automatically. @@ -29,10 +29,10 @@ A net interface configured for user mode is added automatically. By default, the option B<-nographic> is passed to B and one interacts with the serial console of the machine. This configuration is skipped in the presence of this option. -=item B<-i> I, B<--image>=I +=item B<-i> F, B<--image>=F This option specifies the location of the virtual machine image file. -By default B in the working directory is used. +By default F in the working directory is used. =item B<-s> I, B<--sshport>=I @@ -51,10 +51,10 @@ One possible use of this method is passing B<-snapshot> to avoid modifying the v =head1 EXAMPLES -Run a virtual machine stored in the image B (the default) with +Run a virtual machine stored in the image F (the default) with local port 8022 routed to port 22 of the virtual machine. The B<-snapshot> argument is passed to QEMU and prevents any permanent changes to -B, resulting in an ephemeral run. +F, resulting in an ephemeral run. debvm-run -s 8022 -i rootfs.ext4 -- -snapshot -- cgit v1.2.3 From 3a6e67783cfa816c37e02b5eea8ef7607e680b6a Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sun, 8 Jan 2023 10:33:24 +0100 Subject: debvm-waitssh: add --quiet option --- debvm-waitssh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/debvm-waitssh b/debvm-waitssh index 4d69657..857a958 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -9,7 +9,7 @@ debvm-waitssh - Wait for a ssh server to be reachable =head1 SYNOPSIS -B [B<-t> I] [I:]I +B [B<-q>] [B<-t> I] [I:]I =head1 DESCRIPTION @@ -25,6 +25,10 @@ If no hostname is given, B<127.0.0.1> is assumed. Set the maximum duration for waiting in seconds. Defaults to one minute. +=item B<-q>, B<--quiet> + +Be quiet. Output nothing on standard error, not even error messages. + =back =head1 EXIT VALUES @@ -57,6 +61,7 @@ set -u TOTALTIMEOUT=60 SCANTIMEOUT=10 SCANDELAY=1 +VERBOSITY=1 nth_arg() { shift "$1" @@ -68,7 +73,7 @@ die() { exit 2 } usage() { - die "usage: $0 [-t ] [:]" + die "usage: $0 [-q] [-t ] [:]" } usage_error() { echo "error: $*" >&2 @@ -79,8 +84,13 @@ opt_timeout() { TOTALTIMEOUT=$1 } -while getopts :t:-: OPTCHAR; do +opt_verbosity() { + VERBOSITY=$1 +} + +while getopts :qt:-: OPTCHAR; do case "$OPTCHAR" in + q) opt_verbosity 0;; t) opt_timeout "$OPTARG" ;; -) case "$OPTARG" in @@ -95,6 +105,9 @@ while getopts :t:-: OPTCHAR; do timeout=) "opt_${OPTARG%%=*}" "${OPTARG#*=}" ;; + quiet) + opt_verbosity 0 + ;; *) usage_error "unrecognized option --$OPTARG" ;; -- cgit v1.2.3 From f8e1cadb4ef1d63b1b7252d84b9e7234f55b2f6e Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sun, 8 Jan 2023 10:33:55 +0100 Subject: debvm-waitssh: output error message if timeout is reached --- debvm-waitssh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/debvm-waitssh b/debvm-waitssh index 857a958..bde1a93 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -153,5 +153,8 @@ while test "$now" -lt "$deadline"; do now=$(date +%s) fi done +if [ "$VERBOSITY" -ge 1 ]; then + echo "$0: timeout reached trying to contact $HOST:$PORT after waiting $TOTALTIMEOUT seconds." >&2 +fi exit 1 -- cgit v1.2.3 From 8c488b7655b924066930b57b4a0d2ff8be4296b6 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sun, 8 Jan 2023 10:36:00 +0100 Subject: debvm-waitssh: error out if port number is not a positive integer --- debvm-waitssh | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/debvm-waitssh b/debvm-waitssh index bde1a93..a35c783 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -142,6 +142,19 @@ case "$1" in ;; esac +# Guard against strings containing anything but digits, strings starting with +# zero and empty strings as the port number. +# +# We cannot use [!0-9] because that matches on any character (or possibly +# multi-character collation element) that sorts in between 0 and 9. +case "$PORT" in *[!0123456789]*|0?*|""|??????*) + if [ "$VERBOSITY" -ge 1 ]; then + echo "$0: port '$PORT' is not a positive integer between 1 and 99999" >&2 + fi + exit 1 + ;; +esac + now=$(date +%s) deadline=$((now + TOTALTIMEOUT)) while test "$now" -lt "$deadline"; do -- cgit v1.2.3 From 96349ad9ccb4a9c58c4cb32fefcf89d1a76a224f Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sun, 8 Jan 2023 20:45:42 +0100 Subject: debvm-waitssh: error out if hostname contains @ character --- debvm-waitssh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/debvm-waitssh b/debvm-waitssh index a35c783..32db862 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -14,7 +14,8 @@ B [B<-q>] [B<-t> I] [I:]I =head1 DESCRIPTION B can be used to wait for a virtual machine with exposed ssh port to be reachable on that port. -If no hostname is given, B<127.0.0.1> is assumed. +If no hostname is given, B<127.0.0.1> is assumed. No authentication is attempted by B, so neither +a username nor a key have to be supplied. =head1 OPTIONS @@ -142,6 +143,14 @@ case "$1" in ;; esac +case "$HOST" in *@*) + if [ "$VERBOSITY" -ge 1 ]; then + echo "$0: hostname '$HOST' must not contain the '@' character. No username is required." >&2 + fi + exit 1 + ;; +esac + # Guard against strings containing anything but digits, strings starting with # zero and empty strings as the port number. # -- cgit v1.2.3 From fa7ce55eb2d61dfd3a6e8056f6217a5888c2798b Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 8 Jan 2023 20:56:46 +0100 Subject: debvm-waitssh: standardize option parser An option --foo is handled by opt_foo. --- debvm-waitssh | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/debvm-waitssh b/debvm-waitssh index 32db862..246db17 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -81,22 +81,25 @@ usage_error() { usage } +opt_help() { + # shellcheck disable=SC2317 # not dead, called as "opt_$OPTARG" + usage +} +opt_quiet() { + VERBOSITY=0 +} opt_timeout() { TOTALTIMEOUT=$1 } -opt_verbosity() { - VERBOSITY=$1 -} - while getopts :qt:-: OPTCHAR; do case "$OPTCHAR" in - q) opt_verbosity 0;; + q) opt_quiet ;; t) opt_timeout "$OPTARG" ;; -) case "$OPTARG" in - help) - usage + help|quiet) + "opt_$OPTARG" ;; timeout) test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG" @@ -106,9 +109,6 @@ while getopts :qt:-: OPTCHAR; do timeout=) "opt_${OPTARG%%=*}" "${OPTARG#*=}" ;; - quiet) - opt_verbosity 0 - ;; *) usage_error "unrecognized option --$OPTARG" ;; -- cgit v1.2.3 From 85026e3f708d163c90c623cad6c93024b357fc4e Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 8 Jan 2023 20:59:12 +0100 Subject: debvm-waitssh: bad usage should result in exit 2 --- debvm-waitssh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debvm-waitssh b/debvm-waitssh index 246db17..e4f05ee 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -147,7 +147,7 @@ case "$HOST" in *@*) if [ "$VERBOSITY" -ge 1 ]; then echo "$0: hostname '$HOST' must not contain the '@' character. No username is required." >&2 fi - exit 1 + exit 2 ;; esac @@ -160,7 +160,7 @@ case "$PORT" in *[!0123456789]*|0?*|""|??????*) if [ "$VERBOSITY" -ge 1 ]; then echo "$0: port '$PORT' is not a positive integer between 1 and 99999" >&2 fi - exit 1 + exit 2 ;; esac -- cgit v1.2.3 From 6954937b2288ece3d98a034c5764644c50550a30 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 8 Jan 2023 21:04:15 +0100 Subject: debvm-waitssh: don't apply -q to usage errors and further port check --- debvm-waitssh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/debvm-waitssh b/debvm-waitssh index e4f05ee..9e61a64 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -28,7 +28,8 @@ Defaults to one minute. =item B<-q>, B<--quiet> -Be quiet. Output nothing on standard error, not even error messages. +Be quiet. +Do not output a message when the timeout has been reached without success. =back @@ -144,12 +145,8 @@ case "$1" in esac case "$HOST" in *@*) - if [ "$VERBOSITY" -ge 1 ]; then - echo "$0: hostname '$HOST' must not contain the '@' character. No username is required." >&2 - fi - exit 2 - ;; -esac + die "$0: hostname '$HOST' must not contain the '@' character. No username is required." +;; esac # Guard against strings containing anything but digits, strings starting with # zero and empty strings as the port number. @@ -157,12 +154,11 @@ esac # We cannot use [!0-9] because that matches on any character (or possibly # multi-character collation element) that sorts in between 0 and 9. case "$PORT" in *[!0123456789]*|0?*|""|??????*) - if [ "$VERBOSITY" -ge 1 ]; then - echo "$0: port '$PORT' is not a positive integer between 1 and 99999" >&2 - fi - exit 2 - ;; -esac + die "$0: port '$PORT' is not a positive integer between 1 and 65535" +;; esac +if test "$PORT" -lt 1 -o "$PORT" -gt 65535; then + die "$0: port '$PORT' is not a positive integer between 1 and 65535" +fi now=$(date +%s) deadline=$((now + TOTALTIMEOUT)) -- cgit v1.2.3 From 2e2c253fde025921807d37d733f02e3777452da0 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Sun, 8 Jan 2023 21:43:19 +0100 Subject: debvm-waitssh: remove redundant adjective 'positive' from error message --- debvm-waitssh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debvm-waitssh b/debvm-waitssh index 9e61a64..82eb14d 100755 --- a/debvm-waitssh +++ b/debvm-waitssh @@ -154,10 +154,10 @@ case "$HOST" in *@*) # We cannot use [!0-9] because that matches on any character (or possibly # multi-character collation element) that sorts in between 0 and 9. case "$PORT" in *[!0123456789]*|0?*|""|??????*) - die "$0: port '$PORT' is not a positive integer between 1 and 65535" + die "$0: port '$PORT' is not an integer between 1 and 65535" ;; esac if test "$PORT" -lt 1 -o "$PORT" -gt 65535; then - die "$0: port '$PORT' is not a positive integer between 1 and 65535" + die "$0: port '$PORT' is not an integer between 1 and 65535" fi now=$(date +%s) -- cgit v1.2.3 From 80b239b821af73f8a74b3694cc116773d37d43d6 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Sun, 8 Jan 2023 22:38:09 +0100 Subject: debvm-create: automatically log in on serial getty --- debvm-create | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/debvm-create b/debvm-create index c6f4b5c..0dc619b 100755 --- a/debvm-create +++ b/debvm-create @@ -320,6 +320,11 @@ if test "$DEBVER" -ge 12; then set -- --hook-dir=/usr/share/mmdebstrap/hooks/merged-usr "$@" fi +set -- \ + '--customize-hook=mkdir "$1/etc/systemd/system/serial-getty@.service.d"' \ + "--customize-hook=sed -n -e '1i[Service]' -e '1iExecStart=' -e 's,^ExecStart=-/sbin/agetty ,&-a root ,p'"' "$1/lib/systemd/system/serial-getty@.service" > "$1/etc/systemd/system/serial-getty@.service.d/autologin.conf"' \ + "$@" + # suite target mirror set -- "$@" "$SUITE" "$IMAGE" "deb $MIRROR $SUITE main" -- cgit v1.2.3 From b161406981c2c9fb72cf5da3108a2c36906c2c01 Mon Sep 17 00:00:00 2001 From: Jochen Sprickerhof Date: Sun, 8 Jan 2023 14:49:21 +0100 Subject: Add FAQ to debvm-run --- debvm-run | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/debvm-run b/debvm-run index c2a3f21..4a4d5ff 100755 --- a/debvm-run +++ b/debvm-run @@ -58,6 +58,23 @@ F, resulting in an ephemeral run. debvm-run -s 8022 -i rootfs.ext4 -- -snapshot +=head1 FAQ + +=over 8 + +=item The debvm-run console renders wrong. + +Get C from an other terminal and run C in the console or use ssh. +Another option is to run C, which is available from the B package. +Also set C<$TERM> to the outside value. + +=item How can I kill debvm-run? + +The wrapped B can be terminated by pressing Ctrl-a x. +Refer to the B manual page for more escape sequences. + +=back + =head1 LIMITATIONS Due to the way kernel and bootloader are being extracted before running B, one cannot upgrade a kernel and then just reboot. -- cgit v1.2.3 From e7c2288400ee78c3ef8c7a92128287c1eff67811 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Wed, 11 Jan 2023 19:51:18 +0100 Subject: debvm-run: fix typo in error path --- debvm-run | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debvm-run b/debvm-run index 4a4d5ff..6f48089 100755 --- a/debvm-run +++ b/debvm-run @@ -149,7 +149,7 @@ while getopts :gi:s:-: OPTCHAR; do usage_error "missing argument for -$OPTARG" ;; '?') - usage_erro "unrecognized option -$OPTARG" + usage_error "unrecognized option -$OPTARG" ;; *) die "internal error while parsing command options, please report a bug" -- cgit v1.2.3