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>
20240612_branch
Leah Rowe 2024-06-08 01:55:15 +01:00
parent 08d0a1d5d8
commit c202dc612e
2 changed files with 27 additions and 22 deletions

View File

@ -6,6 +6,8 @@
export LC_COLLATE=C export LC_COLLATE=C
export LC_ALL=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" tmpdir_was_set="y"
cbdir="src/coreboot/default" cbdir="src/coreboot/default"
ifdtool="elf/ifdtool/default/ifdtool" ifdtool="elf/ifdtool/default/ifdtool"
@ -225,3 +227,27 @@ singletree()
[ -f "$targetfile" ] && return 1 [ -f "$targetfile" ] && return 1
done 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" || :
}

View File

@ -3,7 +3,6 @@
# Copyright (c) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com> # Copyright (c) 2022 Ferass El Hafidi <vitali64pmemail@protonmail.com>
# Copyright (c) 2023-2024 Leah Rowe <leah@libreboot.org> # Copyright (c) 2023-2024 Leah Rowe <leah@libreboot.org>
_ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
_7ztest="a" _7ztest="a"
e6400_unpack="$PWD/src/bios_extract/dell_inspiron_1100_unpacker.py" e6400_unpack="$PWD/src/bios_extract/dell_inspiron_1100_unpacker.py"
@ -115,20 +114,7 @@ fetch()
_dest="${5##*../}" _dest="${5##*../}"
_dl="$vendir/cache/$dlsum" _dl="$vendir/cache/$dlsum"
x_ mkdir -p "${_dl%/*}" download "$dl" "$dl_bkup" "$_dl" "$dlsum"
dl_fail="y"
vendor_checksum "$dlsum" "$_dl" || dl_fail="n"
for url in "$dl" "$dl_bkup"; do
[ "$dl_fail" = "n" ] && break
[ -z "$url" ] && continue
x_ rm -f "$_dl"
curl --location --retry 3 -A "$_ua" "$url" -o "$_dl" || \
wget --tries 3 -U "$_ua" "$url" -O "$_dl" || continue
vendor_checksum "$dlsum" "$_dl" || dl_fail="n"
done
[ "$dl_fail" = "y" ] && \
$err "fetch $dlsum: matched file unavailable"
x_ rm -Rf "${_dl}_extracted" x_ rm -Rf "${_dl}_extracted"
mkdirs "$_dest" "extract_$dl_type" || return 0 mkdirs "$_dest" "extract_$dl_type" || return 0
@ -139,13 +125,6 @@ fetch()
$err "extract_$dl_type (fetch): missing file: '$_dest'" $err "extract_$dl_type (fetch): missing file: '$_dest'"
} }
vendor_checksum()
{
[ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1
printf "Bad checksum for file: %s\n" "$2" 1>&2
rm -f "$2" || :
}
mkdirs() mkdirs()
{ {
e "$1" f && return 1 e "$1" f && return 1