scripts/get_archive: general cleanup

Signed-off-by: Ian Leonard <antonlacon@gmail.com>
This commit is contained in:
Ian Leonard 2018-11-08 19:02:41 +00:00
parent b216c8d545
commit 843cf6fe13

View File

@ -2,38 +2,38 @@
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv) # Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)
_get_file_already_downloaded() { _get_file_already_downloaded() {
[ ! -f $PACKAGE -o ! -f $STAMP_URL -o ! -f $STAMP_SHA ] && return 1 [ ! -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 [ -n "${PKG_SHA256}" -a "$(cat ${STAMP_SHA} 2>/dev/null)" != "${PKG_SHA256}" ] && return 1
return 0 return 0
} }
# Latest file already present, exit now... # Latest file already present, exit now...
_get_file_already_downloaded && exit 0 _get_file_already_downloaded && exit 0
lock_source_dir $1 lock_source_dir "${1}"
# Check again in case of concurrent access - if nothing needs to be downloaded, exit now... # Check again in case of concurrent access - if nothing needs to be downloaded, exit now...
_get_file_already_downloaded && exit 0 _get_file_already_downloaded && exit 0
# At this point, we need to download something... # At this point, we need to download something...
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GET") $1 (archive)\n" ' '>&$SILENT_OUT printf "%${BUILD_INDENT}c $(print_color CLR_GET "GET") ${1} (archive)\n" ' '>&$SILENT_OUT
export BUILD_INDENT=$((${BUILD_INDENT:-1}+$BUILD_INDENT_SIZE)) export BUILD_INDENT=$((${BUILD_INDENT:-1}+${BUILD_INDENT_SIZE}))
PACKAGE_MIRROR="$DISTRO_MIRROR/$PKG_NAME/$PKG_SOURCE_NAME" PACKAGE_MIRROR="${DISTRO_MIRROR}/${PKG_NAME}/${PKG_SOURCE_NAME}"
[ "$VERBOSE" != "yes" ] && WGET_OPT=-q [ "${VERBOSE}" != "yes" ] && WGET_OPT=-q
WGET_CMD="wget --output-file=- --timeout=30 --tries=3 --passive-ftp --no-check-certificate -c $WGET_OPT --progress=bar:force --show-progress -O $PACKAGE" WGET_CMD="wget --output-file=- --timeout=30 --tries=3 --passive-ftp --no-check-certificate -c ${WGET_OPT} --progress=bar:force --show-progress -O ${PACKAGE}"
# 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 to stop wget from using toolchain/lib and loading libssl.so/libcrypto.so instead of host libraries
unset LD_LIBRARY_PATH unset LD_LIBRARY_PATH
rm -f $STAMP_URL $STAMP_SHA rm -f "${STAMP_URL}" "${STAMP_SHA}"
NBWGET=10 NBWGET=10
while [ $NBWGET -gt 0 ]; do while [ ${NBWGET} -gt 0 ]; do
for url in "$PKG_URL" "$PACKAGE_MIRROR"; do for url in "${PKG_URL}" "${PACKAGE_MIRROR}"; do
rm -f $PACKAGE rm -f "${PACKAGE}"
if $WGET_CMD "$url"; then if ${WGET_CMD} "${url}"; then
CALC_SHA256="$(sha256sum $PACKAGE | cut -d" " -f1)" CALC_SHA256=$(sha256sum "${PACKAGE}" | cut -d" " -f1)
[ -z "${PKG_SHA256}" -o "${PKG_SHA256}" = "${CALC_SHA256}" ] && break 2 [ -z "${PKG_SHA256}" -o "${PKG_SHA256}" = "${CALC_SHA256}" ] && break 2
@ -43,11 +43,10 @@ while [ $NBWGET -gt 0 ]; do
NBWGET=$((NBWGET - 1)) NBWGET=$((NBWGET - 1))
done done
if [ $NBWGET -eq 0 ]; then if [ ${NBWGET} -eq 0 ]; then
echo -e "\nCant't get $1 sources : $PKG_URL\n Try later !!" die "\nCant't get ${1} sources : ${PKG_URL}\nTry later!"
exit 1
else else
printf "%${BUILD_INDENT}c $(print_color CLR_INFO "INFO") Calculated checksum: ${CALC_SHA256}\n\n" ' '>&$SILENT_OUT printf "%${BUILD_INDENT}c $(print_color CLR_INFO "INFO") Calculated checksum: ${CALC_SHA256}\n\n" ' '>&$SILENT_OUT
echo "${PKG_URL}" > $STAMP_URL echo "${PKG_URL}" > "${STAMP_URL}"
echo "${CALC_SHA256}" > $STAMP_SHA echo "${CALC_SHA256}" > "${STAMP_SHA}"
fi fi