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 /functions | |
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 'functions')
-rwxr-xr-x | functions/arguments.sh | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/functions/arguments.sh b/functions/arguments.sh index b2089626c..6b3a5d117 100755 --- a/functions/arguments.sh +++ b/functions/arguments.sh @@ -10,11 +10,14 @@ Arguments () { - ARGUMENTS="$(getopt --longoptions breakpoints,color,conffile:,debug,force,help,quiet,usage,verbose,version --name=${PROGRAM} --options c:huv --shell sh -- "${@}")" + local ERR=0 + ARGUMENTS="$(getopt --longoptions breakpoints,color,conffile:,debug,force,help,quiet,usage,verbose,version --name=${PROGRAM} --options c:huv --shell sh -- "${@}")" || ERR=$? - if [ $? -ne 0 ] - then - Echo_error "terminating" >&2 + if [ $ERR -eq 1 ]; then + Echo_error "invalid arguments" + exit 1 + elif [ $ERR -ne 0 ]; then + Echo_error "getop failure" exit 1 fi |