summaryrefslogtreecommitdiff
path: root/include/err.sh
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-12-23 16:16:26 +0000
committerLeah Rowe <leah@libreboot.org>2023-12-23 17:51:32 +0000
commit655d3cdc881f72d2fdd0797ad92edae2f36ac73e (patch)
tree1b93dd5c3ea6ccc88af19871cabf9d9028cc6131 /include/err.sh
parent25f9d9480fb61e0dd860560d46d8d433565aeb01 (diff)
lbmk scripts: general code cleanup/optimisation
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include/err.sh')
-rwxr-xr-xinclude/err.sh21
1 files changed, 7 insertions, 14 deletions
diff --git a/include/err.sh b/include/err.sh
index 6a8afd41..b7a273a6 100755
--- a/include/err.sh
+++ b/include/err.sh
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2022, 2023 Leah Rowe <leah@libreboot.org>
-version=""; versiondate=""; projectname=""; _nogit=""
+version=""; version_=""; versiondate=""; versiondate_=""; projectname=""; _nogit=""
x_() {
[ $# -lt 1 ] || ${@} || err_exit err ${@}
@@ -48,17 +48,11 @@ check_project()
[ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \
--pretty='%ct' HEAD)" || versiondate="${versiondate_}"
- [ -n "${versiondate}" ] || fail "Unknown version date" || \
- err "Unknown version date"
- [ -n "${version}" ] || fail "Unknown version" || \
- err "Unknown version"
- [ -n "${projectname}" ] || fail "Unknown project" || \
- err "Unknown project"
-
- xx_ printf "%s\n" "${version}" > version || \
- x_ printf "%s\n" "${version}" > version
- xx_ printf "%s\n" "${versiondate}" > versiondate || \
- x_ printf "%s\n" "${versiondate}" > versiondate
+ for p in projectname version versiondate; do
+ eval "[ -n \"\$$p\" ] || fail \"$p unset\" || err \"$p unset\""
+ p_="x_ printf \"%s\\n\" \"\$$p\" > $p"
+ eval "x$p_ || $p_"
+ done
export LOCALVERSION="-${projectname}-${version%%-*}"
}
@@ -67,8 +61,7 @@ setvars()
{
_setvars=""
[ $# -lt 2 ] && err "setvars: too few arguments"
- val="${1}"
- shift 1
+ val="${1}" && shift 1
for var in $@; do
_setvars="${var}=\"${val}\"; ${_setvars}"
done