summaryrefslogtreecommitdiff
path: root/include/get.sh
diff options
context:
space:
mode:
Diffstat (limited to 'include/get.sh')
-rw-r--r--include/get.sh72
1 files changed, 35 insertions, 37 deletions
diff --git a/include/get.sh b/include/get.sh
index 6f1b5f1d..6e2e9f8f 100644
--- a/include/get.sh
+++ b/include/get.sh
@@ -2,31 +2,25 @@
# Copyright (c) 2020-2021,2023-2025 Leah Rowe <leah@libreboot.org>
# Copyright (c) 2022 Caleb La Grange <thonkpeasant@protonmail.com>
-eval "`setvars "" loc url bkup_url subcurl subhash subgit subgit_bkup \
- depend subcurl_bkup repofail`"
+eval "$(setvars "" loc url bkup_url subcurl subhash subgit subgit_bkup \
+ depend subcurl_bkup)"
-tmpgit="$xbmklocal/gitclone"
-tmpgitcache="$XBMK_CACHE/tmpgit"
+tmpgit="$xbtmp/gitclone"
+tmpgitcache="$xbtmp/tmpgit"
fetch_targets()
{
- e "src/$project/$tree" d && return 0
-
- printf "Creating %s tree %s\n" "$project" "$tree"
- git_prep "$url" "$bkup_url" "$xbmkpwd/$configdir/$tree/patches" \
- "src/$project/$tree" with_submodules
+ [ -d "src/$project/$tree" ] || git_prep "$url" "$bkup_url" \
+ "$xbmkpwd/$configdir/$tree/patches" "src/$project/$tree" submod; :
}
fetch_project()
{
- eval "`setvars "" xtree`"
- eval "`setcfg "config/git/$project/pkg.cfg"`"
-
- chkvars url bkup_url
+ eval "$(setvars "" xtree)"
+ eval "$(setcfg "config/git/$project/pkg.cfg")"
- [ -n "$xtree" ] && x_ ./mk -f coreboot "$xtree"
+ chkvars url bkup_url && [ -n "$xtree" ] && x_ ./mk -f coreboot "$xtree"
[ -z "$depend" ] || for d in $depend ; do
- printf "'%s' needs '%s'; grabbing '%s'\n" "$project" "$d" "$d"
x_ ./mk -f $d
done
clone_project
@@ -36,7 +30,6 @@ clone_project()
{
loc="$XBMK_CACHE/clone/$project" && singletree "$project" && \
loc="src/$project"
- printf "Downloading project '%s' to '%s'\n" "$project" "$loc"
e "$loc" d missing && remkdir "${tmpgit%/*}" && git_prep \
"$url" "$bkup_url" "$xbmkpwd/config/$project/patches" "$loc"; :
@@ -44,11 +37,13 @@ clone_project()
git_prep()
{
+ printf "Creating code directory, src/%s/%s\n" "$project" "$tree"
+
_patchdir="$3"
_loc="$4" # $1 and $2 are gitrepo and gitrepo_backup
chkvars rev
- xbmkget git "$1" "$2" "$tmpgit" "$rev" "$_patchdir"
+ xbget git "$1" "$2" "$tmpgit" "$rev" "$_patchdir"
if singletree "$project" || [ $# -gt 4 ]; then
dx_ fetch_submodule "$mdir/module.list"
fi
@@ -60,37 +55,39 @@ git_prep()
fetch_submodule()
{
mcfgdir="$mdir/${1##*/}"; eval \
- "`setvars "" subhash subgit subgit_bkup subcurl subcurl_bkup st`"
- eval "`setcfg "$mcfgdir/module.cfg" 0`"
+ "$(setvars "" subhash subgit subgit_bkup subcurl subcurl_bkup st)"
+ eval "$(setcfg "$mcfgdir/module.cfg" 0)"
for xt in git curl; do
_seval="if [ -n \"\$sub$xt\" ] || [ -n \"\$sub${xt}_bkup\" ]"
eval "$_seval; then st=\"\$st \$xt\"; fi"
done
- st="${st# }" && [ "$st" = "git curl" ] && err "$mdir: git+curl defined"
+ st="${st# }" && [ "$st" = "git curl" ] && \
+ err "$mdir: git+curl defined" fetch_submodule "$@"
[ -z "$st" ] && return 0 # subgit/subcurl not defined
chkvars "sub${st}" "sub${st}_bkup" "subhash"
[ "$st" = "git" ] && x_ rm -Rf "$tmpgit/$1"
- eval xbmkget "$st" "\$sub$st" "\$sub${st}_bkup" "$tmpgit/$1" \
+ eval xbget "$st" "\$sub$st" "\$sub${st}_bkup" "$tmpgit/$1" \
"$subhash" "$mdir/${1##*/}/patches"
}
-xbmkget()
+xbget()
{
[ "$1" = "curl" ] || [ "$1" = "copy" ] || [ "$1" = "git" ] || \
- err "Bad dlop (arg 1): xbmkget $*"
-
- echk="f" && [ "$1" = "git" ] && echk="d"
+ err "Bad dlop (arg 1)" xbget "$@"
for url in "$2" "$3"; do
- [ -n "$url" ] || err "empty URL given in: xbmkget $*"
+ [ -n "$url" ] || err "empty URL given in: xbget $*"
try_file "$url" "$@" || continue
- eval "[ -$echk \"$4\" ] || continue"
+ case "$1" in
+ git) [ -d "$4" ] || continue ;;
+ *) [ -f "$4" ] || continue ;;
+ esac
return 0 # successful download/copy
done
- err "$1 $2 $3 $4: not downloaded"; :
+ err "failed to download file/repository" xbget "$@"; :
}
try_file()
@@ -111,7 +108,8 @@ try_file()
eval "[ -$echk \"$cached\" ] || return 1"
if [ "$2" = "git" ]; then
- [ -d "$5" ] || tmpclone "$cached" "$5" "$6" "$7" || return 1
+ [ -d "$5" ] || tmpclone "$cached" "$5" "$6" "$7" || \
+ err "Can't clone final repo" try_file "$@"; :
else
bad_checksum "$6" "$cached" && x_ rm -f "$cached" && return 1
[ "$cached" != "$5" ] && x_ cp "$cached" "$5"
@@ -130,14 +128,14 @@ try_curl()
try_copy()
{
- [ -L "$2" ] && printf "symlink %s (trycp %s)\n" "$2" "$*" && return 1
- [ ! -f "$2" ] && printf "%s missing (trycp %s)\n" "$2" "$*" && return 1
+ e "$2" f missing && return 1; :
( x_ cp "$2" "$1" ) || return 1; :
}
try_git()
{
- gitdest="`findpath "$1"`" || err "Can't get readpath for '$1'"
+ gitdest="$(findpath "$1" || err "Can't get findpath for '$1'")" || \
+ err "failed findpath for '$1'" try_get "$@"
x_ rm -Rf "$tmpgitcache"
[ -d "$gitdest" ] || ( x_ git clone "$2" "$tmpgitcache" ) || return 1
@@ -148,16 +146,16 @@ try_git()
( x_ git -C "$gitdest" remote remove backup ) || :
x_ git -C "$gitdest" remote add main "$4"
x_ git -C "$gitdest" remote add backup "$5"
- ( x_ git -C "$gitdest" fetch --all ) || :
( x_ git -C "$gitdest" pull --all ) || :; :
}
bad_checksum()
{
- [ ! -f "$2" ] && printf "'%s' missing, %s\n" "$2" "$1" 1>&2 && return 0
- csum="$(x_ sha512sum "$2" | awk '{print $1}')" || err "!sha512 '$2' $1"
- [ "$csum" != "$1" ] && printf "BAD SHA512, '%s'; need '%s', got %s\n" \
- "$2" "$1" "$csum" 1>&2 && x_ rm -f "$2" && return 0; return 1
+ e "$2" f missing && return 0
+ csum="$(x_ sha512sum "$2" | awk '{print $1}')" || \
+ err "!sha512 '$2' $1" bad_checksum "$@"
+ [ "$csum" = "$1" ] && return 1; x_ rm -f "$2"
+ printf "BAD SHA512 %s, '%s'; need '%s'\n" "$csum" "$2" "$1" 1>&2
}
tmpclone()