diff options
author | Leah Rowe <leah@libreboot.org> | 2025-05-12 13:13:13 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2025-05-12 13:16:10 +0100 |
commit | 0911a5a5aed9232f8f9d1685e0a12378f21e41fe (patch) | |
tree | 868ae663d37ca469deae07e325b5eccec3188bd8 /include/lib.sh | |
parent | a449afb287f34e23e98a74011dd655357dc4a085 (diff) |
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>
Diffstat (limited to 'include/lib.sh')
-rw-r--r-- | include/lib.sh | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/include/lib.sh b/include/lib.sh index 2f87e8b1..c69825e8 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -50,34 +50,34 @@ xbmkget() _ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" _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" for url in "$1" "$2"; do - [ "$dl_fail" = "n" ] && break - [ -z "$url" ] && continue - x_ rm -f "$cached" - if [ "$_dlop" = "curl" ]; then - curl --location --retry 3 -A "$_ua" "$url" \ - -o "$cached" || wget --tries 3 -U "$_ua" "$url" \ - -O "$cached" || continue - elif [ "$_dlop" = "copy" ]; then - [ -L "$url" ] && \ - printf "dl %s %s %s %s: '%s' is a symlink\n" \ - "$1" "$2" "$3" "$4" "$url" 1>&2 && continue - [ ! -f "$url" ] && \ - printf "dl %s %s %s %s: '%s' not a file\n" \ - "$1" "$2" "$3" "$4" "$url" 1>&2 && continue - cp "$url" "$cached" || continue - else - err "$1 $2 $3 $4: Unsupported dlop type: '$_dlop'" - fi - bad_checksum "$4" "$cached" || dl_fail="n" - done - [ "$dl_fail" = "y" ] && err "$1 $2 $3 $4: not downloaded" - [ "$cached" = "$3" ] || x_ cp "$cached" "$3"; : + [ -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" + if [ "$2" = "curl" ]; then + curl --location --retry 3 -A "$_ua" "$1" -o "$cached" || \ + wget --tries 3 -U "$_ua" "$1" -O "$cached" || return 1 + elif [ "$2" = "copy" ]; then + [ -L "$1" ] && printf "dl %s %s %s %s: '%s' is a symlink\n" \ + "$3" "$4" "$5" "$6" "$1" 1>&2 && return 1 + [ ! -f "$1" ] && printf "dl %s %s %s %s: '%s' not a file\n" \ + "$3" "$4" "$5" "$6" "$1" 1>&2 && return 1 + cp "$1" "$cached" || return 1 + 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() |