mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-18 14:12:44 +02:00
lib.sh: split up xbmkget()
it was too complicated. most of the logic has been moved to a new function, try_file() the for loop is handled by xbmkget(), whereas each try is now handled in try_file() Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
+26
-26
@@ -50,34 +50,34 @@ xbmkget()
|
|||||||
_ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
|
_ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
|
||||||
|
|
||||||
_dlop="curl" && [ $# -gt 4 ] && _dlop="$5"
|
_dlop="curl" && [ $# -gt 4 ] && _dlop="$5"
|
||||||
cached="$XBMK_CACHE/file/$4"
|
|
||||||
dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum
|
|
||||||
bad_checksum "$4" "$cached" 2>/dev/null && dl_fail="y"
|
|
||||||
[ "$dl_fail" = "n" ] && e "$3" f && return 0
|
|
||||||
x_ mkdir -p "${3%/*}" "$XBMK_CACHE/file"
|
x_ mkdir -p "${3%/*}" "$XBMK_CACHE/file"
|
||||||
for url in "$1" "$2"; do
|
for url in "$1" "$2"; do
|
||||||
[ "$dl_fail" = "n" ] && break
|
[ -n "$url" ] && try_file "$url" "$_dlop" "$@" && return 0
|
||||||
[ -z "$url" ] && continue
|
done && err "$1 $2 $3 $4: not downloaded"; :
|
||||||
x_ rm -f "$cached"
|
}
|
||||||
if [ "$_dlop" = "curl" ]; then
|
|
||||||
curl --location --retry 3 -A "$_ua" "$url" \
|
try_file()
|
||||||
-o "$cached" || wget --tries 3 -U "$_ua" "$url" \
|
{
|
||||||
-O "$cached" || continue
|
cached="$XBMK_CACHE/file/$6"
|
||||||
elif [ "$_dlop" = "copy" ]; then
|
dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum
|
||||||
[ -L "$url" ] && \
|
bad_checksum "$6" "$cached" 2>/dev/null && dl_fail="y"
|
||||||
printf "dl %s %s %s %s: '%s' is a symlink\n" \
|
[ "$dl_fail" = "n" ] && e "$5" f && return 0
|
||||||
"$1" "$2" "$3" "$4" "$url" 1>&2 && continue
|
|
||||||
[ ! -f "$url" ] && \
|
x_ rm -f "$cached"
|
||||||
printf "dl %s %s %s %s: '%s' not a file\n" \
|
if [ "$2" = "curl" ]; then
|
||||||
"$1" "$2" "$3" "$4" "$url" 1>&2 && continue
|
curl --location --retry 3 -A "$_ua" "$1" -o "$cached" || \
|
||||||
cp "$url" "$cached" || continue
|
wget --tries 3 -U "$_ua" "$1" -O "$cached" || return 1
|
||||||
else
|
elif [ "$2" = "copy" ]; then
|
||||||
err "$1 $2 $3 $4: Unsupported dlop type: '$_dlop'"
|
[ -L "$1" ] && printf "dl %s %s %s %s: '%s' is a symlink\n" \
|
||||||
fi
|
"$3" "$4" "$5" "$6" "$1" 1>&2 && return 1
|
||||||
bad_checksum "$4" "$cached" || dl_fail="n"
|
[ ! -f "$1" ] && printf "dl %s %s %s %s: '%s' not a file\n" \
|
||||||
done
|
"$3" "$4" "$5" "$6" "$1" 1>&2 && return 1
|
||||||
[ "$dl_fail" = "y" ] && err "$1 $2 $3 $4: not downloaded"
|
cp "$1" "$cached" || return 1
|
||||||
[ "$cached" = "$3" ] || x_ cp "$cached" "$3"; :
|
else
|
||||||
|
err "$3 $4 $5 $6: Unsupported dlop type: '$2'"
|
||||||
|
fi
|
||||||
|
bad_checksum "$6" "$cached" && return 1
|
||||||
|
[ "$cached" = "$5" ] || x_ cp "$cached" "$5"; :
|
||||||
}
|
}
|
||||||
|
|
||||||
bad_checksum()
|
bad_checksum()
|
||||||
|
|||||||
Reference in New Issue
Block a user