Skip to content

Commit 1b5e47a

Browse files
committed
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.
1 parent ce7253a commit 1b5e47a

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

dom0-updates/qubes-dom0-update

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash --
22
set -euo pipefail
33
shopt -s assoc_expand_once
4-
unset YUM_ACTION UPDATEVM shift_amount
4+
unset YUM_ACTION UPDATEVM
55

66
check_template_in_args () {
77
local pkg
@@ -91,25 +91,24 @@ options_with_args=(
9191
[--setopt]=
9292
)
9393

94-
option_takes_arg () {
95-
[[ "$1" =~ ^-[^dexR]*[dexR]$ ]] || [[ -v options_with_args["$1"] ]]
96-
}
97-
9894
# Filter out some dnf options and collect packages list
9995
while [ $# -gt 0 ]; do
100-
shift_amount=1
101-
if option_takes_arg "$1"; then
96+
if [[ -v options_with_args["$1"] ]]; then
10297
if [[ "$#" -lt 2 ]]; then
103-
printf 'Missing argument to %s\n' "$1" >&2
104-
exit 1
105-
fi
106-
shift_amount=2
98+
printf 'Missing argument to %s\n' "$1"
99+
else
100+
printf '%s %q must be passed as %s=%q\n' "$1" "$2" "$1" "$2"
101+
fi >&2
102+
exit 1
103+
elif [[ "$1" =~ ^-[^dexR]*[dexR]$ ]]; then
104+
if [[ "$#" -lt 2 ]]; then
105+
printf 'Missing argument to %q\n' "$1"
106+
else
107+
printf '%q %q must be written as %q%q\n' "$1" "$2" "$1" "$2"
108+
fi >&2
109+
exit 1
107110
fi
108111
case "$1" in
109-
--enablerepo|--disablerepo)
110-
UPDATEVM_OPTS+=("$1=$2")
111-
QVMTEMPLATE_OPTS+=("$1=$2")
112-
;;
113112
--enablerepo=*|\
114113
--disablerepo=*)
115114
UPDATEVM_OPTS+=( "$1" )
@@ -142,10 +141,6 @@ while [ $# -gt 0 ]; do
142141
--force-xen-upgrade)
143142
FORCE_XEN_UPGRADE=1
144143
;;
145-
--action=)
146-
YUM_ACTION=$1
147-
UPDATEVM_OPTS+=( "$1=$2" )
148-
;;
149144
--action=*)
150145
YUM_ACTION=${1#--action=}
151146
UPDATEVM_OPTS+=( "$1" )
@@ -159,17 +154,17 @@ while [ $# -gt 0 ]; do
159154
fi
160155
;;
161156
-*)
162-
YUM_OPTS+=( "${@:1:shift_amount}" )
163-
UPDATEVM_OPTS+=( "${@:1:shift_amount}" )
164-
QVMTEMPLATE_OPTS+=( "${@:1:shift_amount}" )
157+
YUM_OPTS+=( "$1" )
158+
UPDATEVM_OPTS+=( "$1" )
159+
QVMTEMPLATE_OPTS+=( "$1" )
165160
;;
166161
*)
167162
PKGS+=( "${1}" )
168163
UPDATEVM_OPTS+=( "$1" )
169164
: "${YUM_ACTION=install}"
170165
;;
171166
esac
172-
shift "$shift_amount"
167+
shift
173168
done
174169

175170
if [[ "$GUI" = 1 ]]; then

0 commit comments

Comments
 (0)