2019-03-26 15:59:06 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
2018-07-16 20:45:36 +02:00
|
|
|
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)
|
2018-02-25 11:10:45 +00:00
|
|
|
|
|
|
|
_get_file_already_downloaded() {
|
2018-11-08 19:02:41 +00:00
|
|
|
[ ! -f "${PACKAGE}" -o ! -f "${STAMP_URL}" -o ! -f "${STAMP_SHA}" ] && return 1
|
|
|
|
[ -n "${PKG_SHA256}" -a "$(cat ${STAMP_SHA} 2>/dev/null)" != "${PKG_SHA256}" ] && return 1
|
2018-02-25 11:10:45 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Latest file already present, exit now...
|
|
|
|
_get_file_already_downloaded && exit 0
|
|
|
|
|
2018-11-08 19:02:41 +00:00
|
|
|
lock_source_dir "${1}"
|
2018-02-25 11:10:45 +00:00
|
|
|
|
|
|
|
# Check again in case of concurrent access - if nothing needs to be downloaded, exit now...
|
|
|
|
_get_file_already_downloaded && exit 0
|
|
|
|
|
|
|
|
# At this point, we need to download something...
|
2018-11-17 05:45:24 +00:00
|
|
|
build_msg "CLR_GET" "GET" "${1} (archive)" "indent"
|
2018-02-25 11:10:45 +00:00
|
|
|
|
2019-07-06 23:26:36 +01:00
|
|
|
pkg_lock_status "GETPKG" "${PKG_NAME}" "unpack" "downloading package..."
|
|
|
|
|
2018-11-08 19:02:41 +00:00
|
|
|
PACKAGE_MIRROR="${DISTRO_MIRROR}/${PKG_NAME}/${PKG_SOURCE_NAME}"
|
2024-09-08 06:38:25 -04:00
|
|
|
|
|
|
|
[ "${VERBOSE}" != "yes" ] && GET_OPT="--silent --show-error"
|
2024-10-19 02:26:30 -04:00
|
|
|
GET_CMD="curl ${GET_OPT} --fail --connect-timeout 30 --retry 3 --continue-at - --location --max-redirs 5 --output ${PACKAGE}"
|
2018-02-25 11:10:45 +00:00
|
|
|
|
|
|
|
# unset LD_LIBRARY_PATH to stop wget from using toolchain/lib and loading libssl.so/libcrypto.so instead of host libraries
|
|
|
|
unset LD_LIBRARY_PATH
|
|
|
|
|
2018-11-08 19:02:41 +00:00
|
|
|
rm -f "${STAMP_URL}" "${STAMP_SHA}"
|
2018-02-25 11:10:45 +00:00
|
|
|
|
2024-09-08 06:38:25 -04:00
|
|
|
NBGET=10
|
2020-02-15 18:28:33 +01:00
|
|
|
NBCHKS=2
|
2024-09-08 06:38:25 -04:00
|
|
|
while [ ${NBGET} -gt 0 -a ${NBCHKS} -gt 0 ]; do
|
2018-11-08 19:02:41 +00:00
|
|
|
for url in "${PKG_URL}" "${PACKAGE_MIRROR}"; do
|
|
|
|
rm -f "${PACKAGE}"
|
2024-09-08 06:38:25 -04:00
|
|
|
if ${GET_CMD} "${url}"; then
|
2018-11-08 19:02:41 +00:00
|
|
|
CALC_SHA256=$(sha256sum "${PACKAGE}" | cut -d" " -f1)
|
2018-02-25 11:10:45 +00:00
|
|
|
|
2018-04-02 06:45:10 +01:00
|
|
|
[ -z "${PKG_SHA256}" -o "${PKG_SHA256}" = "${CALC_SHA256}" ] && break 2
|
2018-02-25 11:10:45 +00:00
|
|
|
|
2021-08-10 13:08:51 +02:00
|
|
|
if [ "${CHANGE_HASH}" = "yes" ]; then
|
|
|
|
sed -e "s|^PKG_SHA256=.*|PKG_SHA256=\"${CALC_SHA256}\"|" -i "${PKG_DIR}/package.mk"
|
|
|
|
break 2
|
|
|
|
else
|
|
|
|
build_msg "CLR_WARNING" "WARNING" "Incorrect checksum calculated on downloaded file: got ${CALC_SHA256} wanted ${PKG_SHA256}"
|
|
|
|
NBCHKS=$((NBCHKS - 1))
|
|
|
|
fi
|
2018-02-25 11:10:45 +00:00
|
|
|
fi
|
|
|
|
done
|
2024-09-08 06:38:25 -04:00
|
|
|
NBGET=$((NBGET - 1))
|
2018-02-25 11:10:45 +00:00
|
|
|
done
|
|
|
|
|
2024-09-08 06:38:25 -04:00
|
|
|
if [ ${NBGET} -eq 0 -o ${NBCHKS} -eq 0 ]; then
|
2019-08-09 18:35:50 +01:00
|
|
|
die "\nCannot get ${1} sources : ${PKG_URL}\nTry later!"
|
2018-02-25 11:10:45 +00:00
|
|
|
else
|
2018-11-17 05:45:24 +00:00
|
|
|
build_msg "CLR_INFO" "INFO" "Calculated checksum: ${CALC_SHA256}"
|
2018-11-08 19:02:41 +00:00
|
|
|
echo "${PKG_URL}" > "${STAMP_URL}"
|
|
|
|
echo "${CALC_SHA256}" > "${STAMP_SHA}"
|
2018-02-25 11:10:45 +00:00
|
|
|
fi
|