unified checks for variable initialisation

new function chkvars() does the job

Signed-off-by: Leah Rowe <leah@libreboot.org>
audit6-merge1
Leah Rowe 2024-06-14 13:36:31 +01:00
parent 98724d701b
commit 167e1a0fbe
4 changed files with 14 additions and 14 deletions

View File

@ -52,8 +52,7 @@ fetch_project_repo()
eval "$(setvars "" xtree tree_depend)" eval "$(setvars "" xtree tree_depend)"
scan_config "$project" "config/git" scan_config "$project" "config/git"
[ -z "${loc+x}" ] && $err "fetch_project_repo $project: loc not set" chkvars loc url
[ -z "${url+x}" ] && $err "fetch_project_repo $project: url not set"
[ -n "$xtree" ] && [ ! -d "src/coreboot/$xtree" ] && \ [ -n "$xtree" ] && [ ! -d "src/coreboot/$xtree" ] && \
x_ ./update trees -f coreboot "$xtree" x_ ./update trees -f coreboot "$xtree"
@ -87,7 +86,7 @@ git_prep()
_patchdir="$3" # $1 and $2 are gitrepo and gitrepo_backup _patchdir="$3" # $1 and $2 are gitrepo and gitrepo_backup
_loc="$4" _loc="$4"
[ -z "${rev+x}" ] && $err "git_prep $_loc: rev not set" chkvars rev
tmpclone "$1" "$2" "$tmpgit" "$rev" "$_patchdir" tmpclone "$1" "$2" "$tmpgit" "$rev" "$_patchdir"
if singletree "$project" || [ $# -gt 4 ]; then if singletree "$project" || [ $# -gt 4 ]; then
@ -130,9 +129,7 @@ fetch_submodule()
[ -z "$st" ] && return 0 # subrepo/subfile not defined [ -z "$st" ] && return 0 # subrepo/subfile not defined
for mvar in "sub${st}" "sub${st}_bkup" "subhash"; do chkvars "sub${st}" "sub${st}_bkup" "subhash"
eval "[ -n \"\$$mvar\" ] || $err \"$1, $mdir: $mvar unset\""
done
if [ "$st" = "repo" ]; then if [ "$st" = "repo" ]; then
rm -Rf "$tmpgit/$1" || $err "!rm '$mdir' '$1'" rm -Rf "$tmpgit/$1" || $err "!rm '$mdir' '$1'"

View File

@ -41,6 +41,12 @@ setvars()
done done
printf "%s\n" "${_setvars% }" 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 \ eval "$(setvars "" xbmk_release tmpdir _nogit version board boarddir relname \
versiondate threads projectname projectsite aur_notice cfgsdir datadir)" versiondate threads projectname projectsite aur_notice cfgsdir datadir)"
@ -112,7 +118,7 @@ versiondate_="$versiondate"
[ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \ [ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \
--pretty='%ct' HEAD)" || versiondate="$versiondate_" --pretty='%ct' HEAD)" || versiondate="$versiondate_"
for p in projectname version versiondate projectsite; do for p in projectname version versiondate projectsite; do
eval "[ -n \"\$$p\" ] || $err \"$p unset\"" chkvars "$p"
eval "x_ printf \"%s\\n\" \"\$$p\" > $p" eval "x_ printf \"%s\\n\" \"\$$p\" > $p"
done done
relname="$projectname-$version" relname="$projectname-$version"

View File

@ -8,9 +8,7 @@ eval "$(setvars "" MRC_url MRC_url_bkup MRC_hash MRC_board SHELLBALL)"
extract_mrc() extract_mrc()
{ {
[ -z "$MRC_board" ] && $err "extract_mrc $MRC_hash: MRC_board not set" chkvars "MRC_board" "CONFIG_MRC_FILE"
[ -z "$CONFIG_MRC_FILE" ] && $err "$MRC_hash: CONFIG_MRC_FILE unset"
SHELLBALL="chromeos-firmwareupdate-$MRC_board" SHELLBALL="chromeos-firmwareupdate-$MRC_board"
( (
@ -49,7 +47,7 @@ extract_refcode()
# cbfstool changed the attributes scheme for stage files, # cbfstool changed the attributes scheme for stage files,
# incompatible with older versions before coreboot 4.14, # incompatible with older versions before coreboot 4.14,
# so we need coreboot 4.13 cbfstool for certain refcode files # 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%/*}" mkdir -p "${_refdest%/*}" || $err "ref: !mkdir -p ${_refdest%/*}"
"$cbfstoolref" "$appdir/bios.bin" extract \ "$cbfstoolref" "$appdir/bios.bin" extract \

View File

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