From 66ee22a8bca4631191944f439d42b301a81598b8 Mon Sep 17 00:00:00 2001 From: Demi Marie Obenour Date: Sat, 26 Mar 2022 10:28:02 -0400 Subject: [PATCH] Fail if options are passed incorrectly The previous commit tried to fix up incorrectly passed options, but that didn't always work. Instead, try to detect known bad options (on a best-effort basis) and print an error message. --- dom0-updates/qubes-dom0-update | 41 +++++++++++++++------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/dom0-updates/qubes-dom0-update b/dom0-updates/qubes-dom0-update index 70a9fe1c..deea2517 100755 --- a/dom0-updates/qubes-dom0-update +++ b/dom0-updates/qubes-dom0-update @@ -1,7 +1,7 @@ #!/bin/bash -- set -euo pipefail shopt -s assoc_expand_once -unset YUM_ACTION UPDATEVM shift_amount +unset YUM_ACTION UPDATEVM check_template_in_args () { local pkg @@ -91,25 +91,24 @@ options_with_args=( [--setopt]= ) -option_takes_arg () { - [[ "$1" =~ ^-[^dexR]*[dexR]$ ]] || [[ -v options_with_args["$1"] ]] -} - # Filter out some dnf options and collect packages list while [ $# -gt 0 ]; do - shift_amount=1 - if option_takes_arg "$1"; then + if [[ -v options_with_args["$1"] ]]; then if [[ "$#" -lt 2 ]]; then - printf 'Missing argument to %s\n' "$1" >&2 - exit 1 - fi - shift_amount=2 + printf 'Missing argument to %s\n' "$1" + else + printf '%s %q must be passed as %s=%q\n' "$1" "$2" "$1" "$2" + fi >&2 + exit 1 + elif [[ "$1" =~ ^-[^dexR]*[dexR]$ ]]; then + if [[ "$#" -lt 2 ]]; then + printf 'Missing argument to %q\n' "$1" + else + printf '%q %q must be written as %q%q\n' "$1" "$2" "$1" "$2" + fi >&2 + exit 1 fi case "$1" in - --enablerepo|--disablerepo) - UPDATEVM_OPTS+=("$1=$2") - QVMTEMPLATE_OPTS+=("$1=$2") - ;; --enablerepo=*|\ --disablerepo=*) UPDATEVM_OPTS+=( "$1" ) @@ -142,10 +141,6 @@ while [ $# -gt 0 ]; do --force-xen-upgrade) FORCE_XEN_UPGRADE=1 ;; - --action=) - YUM_ACTION=$1 - UPDATEVM_OPTS+=( "$1=$2" ) - ;; --action=*) YUM_ACTION=${1#--action=} UPDATEVM_OPTS+=( "$1" ) @@ -159,9 +154,9 @@ while [ $# -gt 0 ]; do fi ;; -*) - YUM_OPTS+=( "${@:1:shift_amount}" ) - UPDATEVM_OPTS+=( "${@:1:shift_amount}" ) - QVMTEMPLATE_OPTS+=( "${@:1:shift_amount}" ) + YUM_OPTS+=( "$1" ) + UPDATEVM_OPTS+=( "$1" ) + QVMTEMPLATE_OPTS+=( "$1" ) ;; *) PKGS+=( "${1}" ) @@ -169,7 +164,7 @@ while [ $# -gt 0 ]; do : "${YUM_ACTION=install}" ;; esac - shift "$shift_amount" + shift done if [[ "$GUI" = 1 ]]; then