get.sh: reduce the number of eval statements

also split up try_fetch()

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2025-10-02 06:27:39 +01:00
parent be1f4ebb9c
commit 99f2c0fcf9
+81 -58
View File
@@ -20,7 +20,8 @@ fetch_targets()
fetch_project() fetch_project()
{ {
eval "`setvars "" xtree`" xtree=""
eval "`setcfg "config/git/$project/pkg.cfg"`" eval "`setcfg "config/git/$project/pkg.cfg"`"
chkvars url bkup_url chkvars url bkup_url
@@ -80,25 +81,30 @@ fetch_submodule()
eval "`setcfg "$mcfgdir/module.cfg" 0`" eval "`setcfg "$mcfgdir/module.cfg" 0`"
for xt in git curl; do if [ -n "$subgit" ] || [ -n "$subgit_bkup" ]; then
_seval="if [ -n \"\$sub$xt\" ] || [ -n \"\$sub${xt}_bkup\" ]" st="$st git"
eval "$_seval; then st=\"\$st \$xt\"; fi" fi
done if [ -n "$subcurl" ] || [ -n "$subcurl_bkup" ]; then
st="$st curl"
fi
st="${st# }" st="${st# }"
if [ "$st" = "git curl" ]; then if [ "$st" = "git curl" ]; then
err "$mdir: git+curl defined" "fetch_submodule" "$@" err "$mdir: git+curl defined" "fetch_submodule" "$@"
fi fi
if [ -n "$st" ] if [ -z "$st" ]; then
then return 0
chkvars "sub${st}" "sub${st}_bkup" "subhash" fi
if [ "$st" = "git" ]; then chkvars "sub${st}" "sub${st}_bkup" "subhash"
x_ rm -Rf "$tmpgit/$1"
fi
eval xbget "$st" "\$sub$st" "\$sub${st}_bkup" "$tmpgit/$1" \ if [ "$st" = "git" ]; then
x_ rm -Rf "$tmpgit/$1"
xbget "$st" "$subgit" "$subgit_bkup" "$tmpgit/$1" \
"$subhash" "$mdir/${1##*/}/patches"
else
xbget "$st" "$subcurl" "$subcurl_bkup" "$tmpgit/$1" \
"$subhash" "$mdir/${1##*/}/patches" "$subhash" "$mdir/${1##*/}/patches"
fi fi
} }
@@ -139,69 +145,86 @@ xbget()
err "failed to download file/repository" "xbget" "$@"; : err "failed to download file/repository" "xbget" "$@"; :
} }
# TODO: try_fetch is also a bit messy. those eval statements can
# be tidied up, or eval can be dropped entirely.
# (it works much better than the old code, but it's over-engineered)
try_fetch() try_fetch()
{ {
cached="file/$6" if [ "$2" = "git" ]; then
if [ "$2" = "git" ] if ! try_fetch_git "$@"; then
then return 1
# always the main repo as basis for naming, fi
# in case the backup has another name else
if ! try_fetch_file "$@"; then
cached="clone/${3##*/}" return 1
cached="${cached%.git}" fi
fi fi
}
try_fetch_git()
{
# always the main repo as basis for naming,
# in case the backup has another name
cached="clone/${3##*/}"
cached="${cached%.git}"
cached="$XBMK_CACHE/$cached" cached="$XBMK_CACHE/$cached"
x_ mkdir -p "${5%/*}" "${cached%/*}" x_ mkdir -p "${5%/*}" "${cached%/*}"
echk="d" if ! try_$2 "$cached" "$@"; then
if [ "$2" != "git" ]; then return 1
echk="f" elif [ ! -d "$cached" ]; then
if bad_checksum "$6" "$cached" 2>/dev/null; then return 1
x_ rm -f "$cached" fi
if [ ! -d "$5" ]; then
tmpclone "$cached" "$5" "$6" "$7" || \
err "Can't clone final repo" "try_fetch" "$@"; :
fi
if [ ! -d "$5" ]; then
return 1
fi
}
try_fetch_file()
{
cached="file/$6"
cached="$XBMK_CACHE/$cached"
x_ mkdir -p "${5%/*}" "${cached%/*}"
if bad_checksum "$6" "$cached" 2>/dev/null; then
x_ rm -f "$cached"
fi
if [ ! -f "$cached" ]; then
if ! try_$2 "$cached" "$@"; then
return 1
fi fi
fi fi
evalchk="[ -$echk \"$cached\" ] || " if [ -f "$5" ]; then
if [ "$2" = "git" ]; then
evalchk=""
fi
eval "${evalchk}try_$2 \"\$cached\" \"\$@\" || return 1"
if [ "$2" != "git" ] && [ -f "$5" ]; then
if bad_checksum "$6" "$5" 2>/dev/null; then if bad_checksum "$6" "$5" 2>/dev/null; then
x_ cp "$cached" "$5" x_ cp "$cached" "$5"
fi fi
fi fi
eval "[ -$echk \"$cached\" ] || return 1" if [ ! -f "$cached" ]; then
return 1
if [ "$2" = "git" ] elif bad_checksum "$6" "$cached"; then
then x_ rm -f "$cached"
if [ ! -d "$5" ]; then return 1
tmpclone "$cached" "$5" "$6" "$7" || \
err "Can't clone final repo" "try_fetch" "$@"; :
fi
else
if bad_checksum "$6" "$cached"; then
x_ rm -f "$cached"
return 1
fi
if [ "$cached" != "$5" ]; then
x_ cp "$cached" "$5"
fi
if bad_checksum "$6" "$5"; then
x_ rm -f "$5"
return 1
fi
fi fi
eval "[ -$echk \"$5\" ] || return 1" if [ "$cached" != "$5" ]; then
x_ cp "$cached" "$5"
fi
if bad_checksum "$6" "$5"; then
x_ rm -f "$5"
return 1
elif [ ! -f "$5" ]; then
return 1
fi
} }
try_curl() try_curl()