From 167e1a0fbe6765aaa5f5d3dc682709aa3c31260b Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 14 Jun 2024 13:36:31 +0100 Subject: unified checks for variable initialisation new function chkvars() does the job Signed-off-by: Leah Rowe --- include/git.sh | 9 +++------ include/lib.sh | 8 +++++++- include/mrc.sh | 6 ++---- 3 files changed, 12 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/git.sh b/include/git.sh index 46b63014..c1e7b4ba 100755 --- a/include/git.sh +++ b/include/git.sh @@ -52,8 +52,7 @@ fetch_project_repo() eval "$(setvars "" xtree tree_depend)" scan_config "$project" "config/git" - [ -z "${loc+x}" ] && $err "fetch_project_repo $project: loc not set" - [ -z "${url+x}" ] && $err "fetch_project_repo $project: url not set" + chkvars loc url [ -n "$xtree" ] && [ ! -d "src/coreboot/$xtree" ] && \ x_ ./update trees -f coreboot "$xtree" @@ -87,7 +86,7 @@ git_prep() _patchdir="$3" # $1 and $2 are gitrepo and gitrepo_backup _loc="$4" - [ -z "${rev+x}" ] && $err "git_prep $_loc: rev not set" + chkvars rev tmpclone "$1" "$2" "$tmpgit" "$rev" "$_patchdir" if singletree "$project" || [ $# -gt 4 ]; then @@ -130,9 +129,7 @@ fetch_submodule() [ -z "$st" ] && return 0 # subrepo/subfile not defined - for mvar in "sub${st}" "sub${st}_bkup" "subhash"; do - eval "[ -n \"\$$mvar\" ] || $err \"$1, $mdir: $mvar unset\"" - done + chkvars "sub${st}" "sub${st}_bkup" "subhash" if [ "$st" = "repo" ]; then rm -Rf "$tmpgit/$1" || $err "!rm '$mdir' '$1'" diff --git a/include/lib.sh b/include/lib.sh index a329fa3f..3de05c24 100755 --- a/include/lib.sh +++ b/include/lib.sh @@ -41,6 +41,12 @@ setvars() done printf "%s\n" "${_setvars% }" } +chkvars() +{ + for var in $@; do + eval "[ -n "\${$var+x}" ] || \$err \"$var unset\"" + done +} eval "$(setvars "" xbmk_release tmpdir _nogit version board boarddir relname \ versiondate threads projectname projectsite aur_notice cfgsdir datadir)" @@ -112,7 +118,7 @@ versiondate_="$versiondate" [ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \ --pretty='%ct' HEAD)" || versiondate="$versiondate_" for p in projectname version versiondate projectsite; do - eval "[ -n \"\$$p\" ] || $err \"$p unset\"" + chkvars "$p" eval "x_ printf \"%s\\n\" \"\$$p\" > $p" done relname="$projectname-$version" diff --git a/include/mrc.sh b/include/mrc.sh index caf893a7..fddaef5d 100755 --- a/include/mrc.sh +++ b/include/mrc.sh @@ -8,9 +8,7 @@ eval "$(setvars "" MRC_url MRC_url_bkup MRC_hash MRC_board SHELLBALL)" extract_mrc() { - [ -z "$MRC_board" ] && $err "extract_mrc $MRC_hash: MRC_board not set" - [ -z "$CONFIG_MRC_FILE" ] && $err "$MRC_hash: CONFIG_MRC_FILE unset" - + chkvars "MRC_board" "CONFIG_MRC_FILE" SHELLBALL="chromeos-firmwareupdate-$MRC_board" ( @@ -49,7 +47,7 @@ extract_refcode() # cbfstool changed the attributes scheme for stage files, # incompatible with older versions before coreboot 4.14, # so we need coreboot 4.13 cbfstool for certain refcode files - [ -n "$cbfstoolref" ] || $err "$board: MRC_refcode_cbtree not set" + chkvars cbfstoolref mkdir -p "${_refdest%/*}" || $err "ref: !mkdir -p ${_refdest%/*}" "$cbfstoolref" "$appdir/bios.bin" extract \ -- cgit v1.2.1