From 0bb3c596201a42ccee03d6d2b8513b42f850031e Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Fri, 29 Sep 2023 03:20:02 +0100 Subject: update/blobs/*: unified download/checksum logic Use the same logic between blobs/download and blobs/mrc. The logic is taken from blobs/download. Signed-off-by: Leah Rowe --- include/blobutil.sh | 9 +++------ include/fetch.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) create mode 100755 include/fetch.sh (limited to 'include') diff --git a/include/blobutil.sh b/include/blobutil.sh index 6c78b381..182ddf14 100755 --- a/include/blobutil.sh +++ b/include/blobutil.sh @@ -1,8 +1,6 @@ # SPDX-License-Identifier: GPL-3.0-only # SPDX-FileCopyrightText: 2023 Leah Rowe -agent="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" - _7ztest="a" _b="" @@ -10,10 +8,9 @@ blobdir="blobs" appdir="${blobdir}/app" setvars="EC_url=\"\"" -for x in EC_url_bkup EC_hash DL_hash DL_url DL_url_bkup dl_path \ - E6400_VGA_DL_hash E6400_VGA_DL_url E6400_VGA_DL_url_bkup E6400_VGA_offset \ - E6400_VGA_romname SCH5545EC_DL_url SCH5545EC_DL_url_bkup \ - SCH5545EC_DL_hash; do +for x in EC_url_bkup EC_hash DL_hash DL_url DL_url_bkup E6400_VGA_DL_hash \ + E6400_VGA_DL_url E6400_VGA_DL_url_bkup E6400_VGA_offset E6400_VGA_romname \ + SCH5545EC_DL_url SCH5545EC_DL_url_bkup SCH5545EC_DL_hash; do setvars="${setvars}; ${x}=\"\"" done diff --git a/include/fetch.sh b/include/fetch.sh new file mode 100755 index 00000000..08a1d044 --- /dev/null +++ b/include/fetch.sh @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2023 Leah Rowe + +agent="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" +dl_path="" + +fetch() +{ + dl_type="${1}" + dl="${2}" + dl_bkup="${3}" + dlsum="${4}" + dl_path="${5}" + _fail="${6}" + + mkdir -p "${dl_path%/*}" || "${_fail}" "fetch: !mkdir ${dl_path%/*}" + + dl_fail="y" + vendor_checksum "${dlsum}" "${dl_path}" && dl_fail="n" + for url in "${dl}" "${dl_bkup}"; do + [ "${dl_fail}" = "n" ] && break + [ -z "${url}" ] && continue + rm -f "${dl_path}" || "${_fail}" "fetch: !rm -f ${dl_path}" + wget --tries 3 -U "${agent}" "${url}" -O "${dl_path}" || \ + continue + vendor_checksum "${dlsum}" "${dl_path}" && dl_fail="n" + done + [ "${dl_fail}" = "y" ] && \ + "${_fail}" "fetch ${dlsum}: matched file unavailable" + + eval "extract_${dl_type}" +} + +vendor_checksum() +{ + if [ "$(sha512sum ${2} | awk '{print $1}')" != "${1}" ]; then + printf "Bad checksum for file: %s\n" "${2}" 1>&2 + rm -f "${2}" || : + return 1 + fi +} -- cgit v1.2.1