mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-11 05:52:36 +02:00
lib.sh: move xbmkget() to git.sh
in cbmk, it's only used from there. in lbmk, it's also used from vendor.sh. however, i plan to further expand git.sh at some point, tidying it up so that git cloning is also done from xbmkget, with dlop=git and git.sh would then be renamed to get.sh Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -87,6 +87,56 @@ fetch_submodule()
|
|||||||
"$mdir/${1##*/}/patches"
|
"$mdir/${1##*/}/patches"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# can grab from the internet, or copy locally.
|
||||||
|
# if copying locally, it can only copy a file.
|
||||||
|
xbmkget()
|
||||||
|
{
|
||||||
|
_dlop="curl" && [ $# -gt 4 ] && _dlop="$5"
|
||||||
|
x_ mkdir -p "${3%/*}" "$XBMK_CACHE/file"
|
||||||
|
for url in "$1" "$2"; do
|
||||||
|
[ -n "$url" ] && try_file "$url" "$_dlop" "$@" && return 0
|
||||||
|
done && err "$1 $2 $3 $4: not downloaded"; :
|
||||||
|
}
|
||||||
|
|
||||||
|
try_file()
|
||||||
|
{
|
||||||
|
cached="$XBMK_CACHE/file/$6"
|
||||||
|
dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum
|
||||||
|
bad_checksum "$6" "$cached" 2>/dev/null && dl_fail="y"
|
||||||
|
[ "$dl_fail" = "n" ] && e "$5" f && return 0
|
||||||
|
|
||||||
|
x_ rm -f "$cached"
|
||||||
|
[ "$2" = "curl" ] || [ "$2" = "copy" ] || \
|
||||||
|
err "$3 $4 $5 $6: Unsupported dlop type: '$2'"
|
||||||
|
|
||||||
|
try_$2 "$cached" "$@" || return 1
|
||||||
|
|
||||||
|
bad_checksum "$6" "$cached" && return 1
|
||||||
|
[ "$cached" = "$5" ] || x_ cp "$cached" "$5"; :
|
||||||
|
}
|
||||||
|
|
||||||
|
try_curl()
|
||||||
|
{
|
||||||
|
_ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
|
||||||
|
curl --location --retry 3 -A "$_ua" "$2" -o "$1" || \
|
||||||
|
wget --tries 3 -U "$_ua" "$2" -O "$1" || return 1; :
|
||||||
|
}
|
||||||
|
|
||||||
|
try_copy()
|
||||||
|
{
|
||||||
|
[ -L "$2" ] && printf "dl %s %s %s %s: '%s' is a symlink\n" \
|
||||||
|
"$4" "$5" "$6" "$7" "$2" 1>&2 && return 1
|
||||||
|
[ ! -f "$2" ] && printf "dl %s %s %s %s: '%s' not a file\n" \
|
||||||
|
"$4" "$5" "$6" "$7" "$2" 1>&2 && return 1
|
||||||
|
cp "$2" "$1" || return 1; :
|
||||||
|
}
|
||||||
|
|
||||||
|
bad_checksum()
|
||||||
|
{
|
||||||
|
[ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1
|
||||||
|
printf "Bad checksum for file: %s\n" "$2" 1>&2; rm -f "$2" || :; :
|
||||||
|
}
|
||||||
|
|
||||||
tmpclone()
|
tmpclone()
|
||||||
{
|
{
|
||||||
[ -d "$3" ] && return 0
|
[ -d "$3" ] && return 0
|
||||||
|
|||||||
@@ -35,56 +35,6 @@ rmgit()
|
|||||||
fx_ "x_ rm -Rf" x_ find "$1" -name ".gitmodules"
|
fx_ "x_ rm -Rf" x_ find "$1" -name ".gitmodules"
|
||||||
}
|
}
|
||||||
|
|
||||||
# can grab from the internet, or copy locally.
|
|
||||||
# if copying locally, it can only copy a file.
|
|
||||||
xbmkget()
|
|
||||||
{
|
|
||||||
_dlop="curl" && [ $# -gt 4 ] && _dlop="$5"
|
|
||||||
x_ mkdir -p "${3%/*}" "$XBMK_CACHE/file"
|
|
||||||
for url in "$1" "$2"; do
|
|
||||||
[ -n "$url" ] && try_file "$url" "$_dlop" "$@" && return 0
|
|
||||||
done && err "$1 $2 $3 $4: not downloaded"; :
|
|
||||||
}
|
|
||||||
|
|
||||||
try_file()
|
|
||||||
{
|
|
||||||
cached="$XBMK_CACHE/file/$6"
|
|
||||||
dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum
|
|
||||||
bad_checksum "$6" "$cached" 2>/dev/null && dl_fail="y"
|
|
||||||
[ "$dl_fail" = "n" ] && e "$5" f && return 0
|
|
||||||
|
|
||||||
x_ rm -f "$cached"
|
|
||||||
[ "$2" = "curl" ] || [ "$2" = "copy" ] || \
|
|
||||||
err "$3 $4 $5 $6: Unsupported dlop type: '$2'"
|
|
||||||
|
|
||||||
try_$2 "$cached" "$@" || return 1
|
|
||||||
|
|
||||||
bad_checksum "$6" "$cached" && return 1
|
|
||||||
[ "$cached" = "$5" ] || x_ cp "$cached" "$5"; :
|
|
||||||
}
|
|
||||||
|
|
||||||
try_curl()
|
|
||||||
{
|
|
||||||
_ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
|
|
||||||
curl --location --retry 3 -A "$_ua" "$2" -o "$1" || \
|
|
||||||
wget --tries 3 -U "$_ua" "$2" -O "$1" || return 1; :
|
|
||||||
}
|
|
||||||
|
|
||||||
try_copy()
|
|
||||||
{
|
|
||||||
[ -L "$2" ] && printf "dl %s %s %s %s: '%s' is a symlink\n" \
|
|
||||||
"$4" "$5" "$6" "$7" "$2" 1>&2 && return 1
|
|
||||||
[ ! -f "$2" ] && printf "dl %s %s %s %s: '%s' not a file\n" \
|
|
||||||
"$4" "$5" "$6" "$7" "$2" 1>&2 && return 1
|
|
||||||
cp "$2" "$1" || return 1; :
|
|
||||||
}
|
|
||||||
|
|
||||||
bad_checksum()
|
|
||||||
{
|
|
||||||
[ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1
|
|
||||||
printf "Bad checksum for file: %s\n" "$2" 1>&2; rm -f "$2" || :; :
|
|
||||||
}
|
|
||||||
|
|
||||||
e()
|
e()
|
||||||
{
|
{
|
||||||
es_t="e" && [ $# -gt 1 ] && es_t="$2"
|
es_t="e" && [ $# -gt 1 ] && es_t="$2"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ fi
|
|||||||
. "include/mrc.sh"
|
. "include/mrc.sh"
|
||||||
. "include/rom.sh"
|
. "include/rom.sh"
|
||||||
. "include/release.sh"
|
. "include/release.sh"
|
||||||
|
. "include/git.sh"
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
@@ -34,7 +35,6 @@ main()
|
|||||||
|
|
||||||
main "$@" || exit 0
|
main "$@" || exit 0
|
||||||
|
|
||||||
. "include/git.sh"
|
|
||||||
. "include/tree.sh"
|
. "include/tree.sh"
|
||||||
|
|
||||||
trees "$@" || exit 0
|
trees "$@" || exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user