diff options
author | Leah Rowe <leah@libreboot.org> | 2023-10-02 09:00:22 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2023-10-02 09:03:10 +0100 |
commit | cb29c96c74b6985ce3cd7f6f672b1d71a88c6fa6 (patch) | |
tree | 1bc993b25a09e9ddfa684a453e9587efb3a48d72 | |
parent | 9dce8236efed907c70c5b216a9f8df8342b1d3b7 (diff) |
lbmk: simplify/correct exit commands / cleanup
general code cleanup, but a few exit commands were also
wrong. for example, relying on listitems to always return
zero status and then calling lbmk_exit 1
Signed-off-by: Leah Rowe <leah@libreboot.org>
-rwxr-xr-x | lbmk | 27 |
1 files changed, 13 insertions, 14 deletions
@@ -39,13 +39,16 @@ initialise_command() mode="${1}" [ "${mode}" != "dependencies" ] || xx_ install_packages $@ - [ "$(id -u)" != "0" ] || \ - fail "running this command as root is not permitted" + [ "$(id -u)" != "0" ] || fail "this command as root is not permitted" [ "${mode}" = "help" ] && usage ${0} && lbmk_exit 0 - [ "${mode}" = "list" ] && listitems "${buildpath}" && \ - lbmk_exit 0 - [ $# -lt 2 ] && usage ${0} && lbmk_exit 1 + if [ "${mode}" = "list" ]; then + listitems "${buildpath}" + lbmk_exit 0 + elif [ $# -lt 2 ]; then + usage ${0} + lbmk_exit 1 + fi option="${2}" } @@ -54,8 +57,7 @@ install_packages() { if [ $# -lt 2 ]; then printf "You must specify a distro, namely:\n" 1>&2 - printf "Look at files under config/dependencies/\n" \ - 1>&2 + printf "Look at files under config/dependencies/\n" 1>&2 printf "Example: ./build dependencies debian\n" 1>&2 fail "install_packages: target not specified" fi @@ -105,23 +107,20 @@ usage() lbmk_exit() { - tmp_cleanup || \ - err "lbmk_exit: could not remove tmpdir upon exit $1: ${tmpdir}" + tmp_cleanup || err "lbmk_exit: can't rm tmpdir upon exit $1: ${tmpdir}" exit $1 } fail() { - tmp_cleanup || printf "fail(): WARNING: cannot remove tmpdir: %s\n" \ - "${tmpdir}" 1>&2 + tmp_cleanup || printf "WARNING: can't rm tmpdir: %s\n" "${tmpdir}" 1>&2 err "${1}" } tmp_cleanup() { - if [ "${tmpdir_was_set}" = "n" ]; then - rm -Rf "${tmpdir}" || return 1 - fi + [ "${tmpdir_was_set}" = "n" ] || return 0 + rm -Rf "${tmpdir}" || return 1 } main $@ |