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>btrfsvols
parent
9dce8236ef
commit
cb29c96c74
23
lbmk
23
lbmk
|
@ -39,13 +39,16 @@ initialise_command()
|
||||||
|
|
||||||
mode="${1}"
|
mode="${1}"
|
||||||
[ "${mode}" != "dependencies" ] || xx_ install_packages $@
|
[ "${mode}" != "dependencies" ] || xx_ install_packages $@
|
||||||
[ "$(id -u)" != "0" ] || \
|
[ "$(id -u)" != "0" ] || fail "this command as root is not permitted"
|
||||||
fail "running this command as root is not permitted"
|
|
||||||
|
|
||||||
[ "${mode}" = "help" ] && usage ${0} && lbmk_exit 0
|
[ "${mode}" = "help" ] && usage ${0} && lbmk_exit 0
|
||||||
[ "${mode}" = "list" ] && listitems "${buildpath}" && \
|
if [ "${mode}" = "list" ]; then
|
||||||
|
listitems "${buildpath}"
|
||||||
lbmk_exit 0
|
lbmk_exit 0
|
||||||
[ $# -lt 2 ] && usage ${0} && lbmk_exit 1
|
elif [ $# -lt 2 ]; then
|
||||||
|
usage ${0}
|
||||||
|
lbmk_exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
option="${2}"
|
option="${2}"
|
||||||
}
|
}
|
||||||
|
@ -54,8 +57,7 @@ install_packages()
|
||||||
{
|
{
|
||||||
if [ $# -lt 2 ]; then
|
if [ $# -lt 2 ]; then
|
||||||
printf "You must specify a distro, namely:\n" 1>&2
|
printf "You must specify a distro, namely:\n" 1>&2
|
||||||
printf "Look at files under config/dependencies/\n" \
|
printf "Look at files under config/dependencies/\n" 1>&2
|
||||||
1>&2
|
|
||||||
printf "Example: ./build dependencies debian\n" 1>&2
|
printf "Example: ./build dependencies debian\n" 1>&2
|
||||||
fail "install_packages: target not specified"
|
fail "install_packages: target not specified"
|
||||||
fi
|
fi
|
||||||
|
@ -105,23 +107,20 @@ usage()
|
||||||
|
|
||||||
lbmk_exit()
|
lbmk_exit()
|
||||||
{
|
{
|
||||||
tmp_cleanup || \
|
tmp_cleanup || err "lbmk_exit: can't rm tmpdir upon exit $1: ${tmpdir}"
|
||||||
err "lbmk_exit: could not remove tmpdir upon exit $1: ${tmpdir}"
|
|
||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
fail()
|
fail()
|
||||||
{
|
{
|
||||||
tmp_cleanup || printf "fail(): WARNING: cannot remove tmpdir: %s\n" \
|
tmp_cleanup || printf "WARNING: can't rm tmpdir: %s\n" "${tmpdir}" 1>&2
|
||||||
"${tmpdir}" 1>&2
|
|
||||||
err "${1}"
|
err "${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_cleanup()
|
tmp_cleanup()
|
||||||
{
|
{
|
||||||
if [ "${tmpdir_was_set}" = "n" ]; then
|
[ "${tmpdir_was_set}" = "n" ] || return 0
|
||||||
rm -Rf "${tmpdir}" || return 1
|
rm -Rf "${tmpdir}" || return 1
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main $@
|
main $@
|
||||||
|
|
Loading…
Reference in New Issue