diff options
author | Helmut Grohne <helmut@subdivi.de> | 2022-12-28 10:09:06 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2022-12-28 10:09:06 +0100 |
commit | 1f16c8718bebb1f4a3065599581dad392f6afc94 (patch) | |
tree | 9046fb0fe7ec5c2e84f1b7149fec9996e4d3db20 /debvm-run | |
parent | 0c50e3b74ec8173d6b0b5f26250a8feee0ceda7b (diff) | |
parent | b666a2909890a7954b103388ec846cac8ce55722 (diff) | |
download | debvm-1f16c8718bebb1f4a3065599581dad392f6afc94.tar.gz |
Merge branch main into branch pod2man
This merge picks up long options and the -s to -z rename.
Diffstat (limited to 'debvm-run')
-rwxr-xr-x | debvm-run | 70 |
1 files changed, 49 insertions, 21 deletions
@@ -66,40 +66,68 @@ IMAGE=rootfs.ext4 SSHPORT= GRAPHICAL= +nth_arg() { + shift "$1" + printf "%s" "$1" +} + die() { echo "$*" 1>&2 exit 1 } - usage() { die "usage: $0 [-g] [-i image] [-s sshport] [-- qemu options]" } +usage_error() { + echo "error: $*" 1>&2 + usage +} -while test "$#" -gt 0; do - case "$1" in - -g) - GRAPHICAL=1 - shift - ;; - -i) - test "$#" -eq 1 && usage - IMAGE=$2 - shift 2 +opt_graphical() { + GRAPHICAL=1 +} +opt_image() { + IMAGE=$1 +} +opt_sshport() { + SSHPORT=$1 +} + +while getopts :gi:s:-: OPTCHAR; do + case "$OPTCHAR" in + g) opt_graphical ;; + i) opt_image "$OPTARG" ;; + s) opt_sshport "$OPTARG" ;; + -) + case "$OPTARG" in + help) + usage + ;; + graphical|image|sshport) + test "$OPTIND" -gt "$#" && usage_error "missing argument for --$OPTARG" + "opt_$OPTARG" "$(nth_arg "$OPTIND" "$@")" + OPTIND=$((OPTIND+1)) + ;; + image=*|sshport=*) + "opt_${OPTARG%%=*}" "${OPTARG#*=}" + ;; + *) + usage_error "unrecognized option --$OPTARG" + ;; + esac ;; - -s) - test "$#" -eq 1 && usage - SSHPORT=$2 - shift 2 + :) + usage_error "missing argument for -$OPTARG" ;; - --) - shift - break + '?') + usage_erro "unrecognized option -$OPTARG" ;; *) - usage + die "internal error while parsing command options, please report a bug" ;; esac done +shift "$((OPTIND - 1))" test -f "$IMAGE" || die "image '$IMAGE' not found" test -s "$IMAGE" || die "image '$IMAGE' is empty" @@ -198,9 +226,9 @@ else ;; esac fi -if test "$MAX_SMP" -gt 1; then +if test -z "$MAX_SMP" || test "$MAX_SMP" -gt 1; then NPROC=$(nproc) - test "$NPROC" -gt "$MAX_SMP" && NPROC=$MAX_SMP + test -n "$MAX_SMP" && test "$NPROC" -gt "$MAX_SMP" && NPROC=$MAX_SMP set -- -smp "$NPROC" "$@" fi |