vendor.sh: move some functions to vendor/download

they are the functions only used by the download
script, so they don't belong in vendor.sh

an include file should only contain variables and
functions used by multiple main scripts

Signed-off-by: Leah Rowe <leah@libreboot.org>
btrfsvols
Leah Rowe 2023-10-15 10:00:23 +01:00
parent 0f807762a2
commit d8c2c24507
2 changed files with 61 additions and 61 deletions

View File

@ -40,64 +40,3 @@ check_defconfig()
done done
return 1 return 1
} }
fetch()
{
dl_type="${1}"
dl="${2}"
dl_bkup="${3}"
dlsum="${4}"
[ "${5# }" = "${5}" ] || err "fetch: space not allowed in _dest: '${5}'"
[ "${5#/}" = "${5}" ] || err "fetch: absolute path not allowed: '${5}'"
_dest="${5##*../}"
_dl="${vendir}/cache/${dlsum}"
x_ mkdir -p "${_dl%/*}"
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"
mkdirs "${_dest}" "extract_${dl_type}" || return 0
eval "extract_${dl_type}"
[ -f "${_dest}" ] && return 0
err "extract_${dl_type} (fetch): missing file: '${_dest}'"
}
vendor_checksum()
{
[ "$(sha512sum ${2} | awk '{print $1}')" != "${1}" ] || return 0
printf "Bad checksum for file: %s\n" "${2}" 1>&2
rm -f "${2}" || :
return 1
}
mkdirs()
{
[ -f "${1}" ] && \
printf "mkdirs ${1} ${2}: already downloaded\n" 1>&2 && return 1
x_ mkdir -p "${1%/*}"
x_ rm -Rf "${appdir}"
x_ mkdir -p "${appdir}/"
extract_archive "${_dl}" "${appdir}" || \
[ "${2}" = "extract_e6400vga" ] || err "mkdirs ${1} ${2}: !extract"
}
extract_archive()
{
innoextract "${1}" -d "${2}" || python "${pfs_extract}" "${1}" -e || \
7z x "${1}" -o"${2}" || unar "${1}" -o "${2}" || \
unzip "${1}" -d "${2}" || return 1
}

View File

@ -76,6 +76,60 @@ download_vendorfiles()
"${CONFIG_MRC_FILE}" "${CONFIG_MRC_FILE}"
} }
fetch()
{
dl_type="${1}"
dl="${2}"
dl_bkup="${3}"
dlsum="${4}"
[ "${5# }" = "${5}" ] || err "fetch: space not allowed in _dest: '${5}'"
[ "${5#/}" = "${5}" ] || err "fetch: absolute path not allowed: '${5}'"
_dest="${5##*../}"
_dl="${vendir}/cache/${dlsum}"
x_ mkdir -p "${_dl%/*}"
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"
mkdirs "${_dest}" "extract_${dl_type}" || return 0
eval "extract_${dl_type}"
[ -f "${_dest}" ] && return 0
err "extract_${dl_type} (fetch): missing file: '${_dest}'"
}
vendor_checksum()
{
[ "$(sha512sum ${2} | awk '{print $1}')" != "${1}" ] || return 0
printf "Bad checksum for file: %s\n" "${2}" 1>&2
rm -f "${2}" || :
return 1
}
mkdirs()
{
[ -f "${1}" ] && \
printf "mkdirs ${1} ${2}: already downloaded\n" 1>&2 && return 1
x_ mkdir -p "${1%/*}"
x_ rm -Rf "${appdir}"
x_ mkdir -p "${appdir}/"
extract_archive "${_dl}" "${appdir}" || \
[ "${2}" = "extract_e6400vga" ] || err "mkdirs ${1} ${2}: !extract"
}
extract_intel_me() extract_intel_me()
{ {
_me="${PWD}/${_dest}" # must always be an absolute path _me="${PWD}/${_dest}" # must always be an absolute path
@ -111,6 +165,13 @@ extract_intel_me()
rm -Rf "${sdir}" || err "extract_intel_me: !rm -Rf ${sdir}" rm -Rf "${sdir}" || err "extract_intel_me: !rm -Rf ${sdir}"
} }
extract_archive()
{
innoextract "${1}" -d "${2}" || python "${pfs_extract}" "${1}" -e || \
7z x "${1}" -o"${2}" || unar "${1}" -o "${2}" || \
unzip "${1}" -d "${2}" || return 1
}
extract_kbc1126ec() extract_kbc1126ec()
{ {
( (