unified checks for variable initialisation

new function chkvars() does the job

Signed-off-by: Leah Rowe <leah@libreboot.org>
audit2-merge1
Leah Rowe 2024-06-14 13:36:31 +01:00 committed by Leah Rowe
parent 1399f2137f
commit bb7b04cb59
3 changed files with 12 additions and 10 deletions

View File

@ -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'"

View File

@ -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"

View File

@ -129,7 +129,7 @@ handle_src_tree()
load_project_config "$target_dir"
x_ mkdir -p "$elfdir/$target"
[ -z "$tree" ] && $err "handle_src_tree $project/$tree: tree unset"
chkvars tree
cdir="src/$project/$tree"
if [ ! -d "$cdir" ]; then
@ -277,8 +277,7 @@ mkpayload_grub()
. "$grubdata/module/$tree" || $err "$tree: !source grub modules"
[ -z "$grub_install_modules" ] && $err "$tree: install modules unset"
[ -z "$grub_modules" ] && $err "$tree: modules unset"
chkvars "grub_install_modules" "grub_modules"
"${cdir}/grub-mkstandalone" --grub-mkimage="${cdir}/grub-mkimage" \
-O i386-coreboot -o "${cdir}/grub.elf" -d "${cdir}/grub-core/" \