Skip to content

Commit

Permalink
Fail if options are passed incorrectly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DemiMarie committed Apr 3, 2022
1 parent fe98408 commit 66ee22a
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions dom0-updates/qubes-dom0-update
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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" )
Expand Down Expand Up @@ -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" )
Expand All @@ -159,17 +154,17 @@ 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}" )
UPDATEVM_OPTS+=( "$1" )
: "${YUM_ACTION=install}"
;;
esac
shift "$shift_amount"
shift
done

if [[ "$GUI" = 1 ]]; then
Expand Down

0 comments on commit 66ee22a

Please sign in to comment.