diff options
author | Leah Rowe <leah@libreboot.org> | 2024-06-08 01:55:15 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2024-06-08 01:55:15 +0100 |
commit | c202dc612e76aa5850bc9e8000832e7085b84840 (patch) | |
tree | 2523ed3fa7d2bb968830bef83b4388120a93ed47 /include/lib.sh | |
parent | 08d0a1d5d824b69cc6bf45596fe921d52ff179c5 (diff) |
vendor.sh: move download logic to lib.sh
in future revisions, i will make tarballs become subfiles,
to complement submodules. e.g. crossgcc tarballs in coreboot
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include/lib.sh')
-rwxr-xr-x | include/lib.sh | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/lib.sh b/include/lib.sh index dac8e507..9d66ea8d 100755 --- a/include/lib.sh +++ b/include/lib.sh @@ -6,6 +6,8 @@ export LC_COLLATE=C export LC_ALL=C +_ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" + tmpdir_was_set="y" cbdir="src/coreboot/default" ifdtool="elf/ifdtool/default/ifdtool" @@ -225,3 +227,27 @@ singletree() [ -f "$targetfile" ] && return 1 done } + +download() +{ + dl_fail="y" # 1 url, 2 url backup, 3 destination, 4 checksum + vendor_checksum "$4" "$3" || dl_fail="n" + [ "$dl_fail" = "n" ] && e "$3" f && return 0 + x_ mkdir -p "${3%/*}" + for url in "$1" "$2"; do + [ "$dl_fail" = "n" ] && break + [ -z "$1" ] && continue + x_ rm -f "$3" + curl --location --retry 3 -A "$_ua" "$1" -o "$3" || \ + wget --tries 3 -U "$_ua" "$1" -O "$3" || continue + vendor_checksum "$4" "$3" || dl_fail="n" + done + [ "$dl_fail" = "y" ] && $err "$1 $2 $3 $4: file missing"; return 0 +} + +vendor_checksum() +{ + [ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1 + printf "Bad checksum for file: %s\n" "$2" 1>&2 + rm -f "$2" || : +} |