diff options
author | Lyndon Brown <jnqnfe@gmail.com> | 2020-03-06 23:16:26 +0000 |
---|---|---|
committer | Luca Boccassi <bluca@debian.org> | 2020-03-10 12:45:23 +0000 |
commit | cf2a9b951cbd4e6bc35ea0d389f39c0ec36db639 (patch) | |
tree | 61147b582268ee5f72c9d3604f12c36c74906ece /scripts/build | |
parent | d6096622f9f7f9e2e1c8b01b4769c9d08487688e (diff) | |
download | vyos-live-build-cf2a9b951cbd4e6bc35ea0d389f39c0ec36db639.tar.gz vyos-live-build-cf2a9b951cbd4e6bc35ea0d389f39c0ec36db639.zip |
arguments: fix unreachable and poor argument error handling
all scripts use `set -e` which means that if getop fails, the subsequent
error check that would print an error in addition to any printed by getopt
itself would never actually be reached.
the first though here would be to remove the pointless error check, but
getopt does not include the word "error" with an unrecognised option
failure, nor does it use colour to highlight problems, both of which mean
that it is a little lacking in terms of highlighting problems to users.
thus we properly capture and use the exit code here and output an
appropriate message per invalid argument vs getopt internal error.
also, removed the redundant stderr redirection which is already done
by Echo_error().
Gbp-Dch: Short
Diffstat (limited to 'scripts/build')
-rwxr-xr-x | scripts/build/config | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/scripts/build/config b/scripts/build/config index ce4a24542..b30223457 100755 --- a/scripts/build/config +++ b/scripts/build/config @@ -164,10 +164,15 @@ Local_arguments () bootstrap-qemu-exclude:" # Remove spaces added by indentation LONG_OPTIONS="$(echo ${LONG_OPTIONS} | tr -d ' ')" - ARGUMENTS="$(getopt --longoptions ${LONG_OPTIONS} --name="${PROGRAM}" --options a:d:m:k:b:s:c:huv --shell sh -- "${@}")" - if [ $? -ne 0 ]; then - Echo_error "terminating" >&2 + local ERR=0 + ARGUMENTS="$(getopt --longoptions ${LONG_OPTIONS} --name="${PROGRAM}" --options a:d:m:k:b:s:c:huv --shell sh -- "${@}")" || ERR=$? + + if [ $ERR -eq 1 ]; then + Echo_error "invalid arguments" + exit 1 + elif [ $ERR -ne 0 ]; then + Echo_error "getop failure" exit 1 fi |