scripts/get: support get handlers, starting with get_archive

This commit is contained in:
MilhouseVH 2018-02-25 11:10:45 +00:00
parent 0f2340763a
commit 3d1713527c
4 changed files with 129 additions and 79 deletions

View File

@ -98,24 +98,28 @@ if [ -n "$PKG_URL" -a -z "$PKG_SOURCE_NAME" ]; then
echo "$PKG_URL" echo "$PKG_URL"
exit 1 exit 1
fi fi
PKG_SOURCE_NAME="${PKG_URL##*/}" if [[ ${PKG_URL} =~ .git$ || ${PKG_URL} =~ ^git:// ]]; then
case $PKG_SOURCE_NAME in PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.tar.gz
${PKG_NAME}-${PKG_VERSION}.*) else
PKG_SOURCE_NAME=$PKG_SOURCE_NAME PKG_SOURCE_NAME="${PKG_URL##*/}"
;; case $PKG_SOURCE_NAME in
*.tar | *.tbz | *.tgz | *.txz | *.7z | *.zip) ${PKG_NAME}-${PKG_VERSION}.*)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.${PKG_SOURCE_NAME##*\.} PKG_SOURCE_NAME=$PKG_SOURCE_NAME
;; ;;
*.tar.bz2 | *.tar.gz | *.tar.xz) *.tar | *.tbz | *.tgz | *.txz | *.7z | *.zip)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.tar.${PKG_SOURCE_NAME##*\.} PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.${PKG_SOURCE_NAME##*\.}
;; ;;
*.diff | *.patch | *.diff.bz2 | *.patch.bz2 | patch-*.bz2 | *.diff.gz | *.patch.gz | patch-*.gz) *.tar.bz2 | *.tar.gz | *.tar.xz)
PKG_SOURCE_NAME=$PKG_SOURCE_NAME PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.tar.${PKG_SOURCE_NAME##*\.}
;; ;;
*) *.diff | *.patch | *.diff.bz2 | *.patch.bz2 | patch-*.bz2 | *.diff.gz | *.patch.gz | patch-*.gz)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.${PKG_SOURCE_NAME##*\.} PKG_SOURCE_NAME=$PKG_SOURCE_NAME
;; ;;
esac *)
PKG_SOURCE_NAME=${PKG_NAME}-${PKG_VERSION}.${PKG_SOURCE_NAME##*\.}
;;
esac
fi
fi fi
PKG_BUILD="$BUILD/${PKG_NAME}-${PKG_VERSION}" PKG_BUILD="$BUILD/${PKG_NAME}-${PKG_VERSION}"

View File

@ -207,3 +207,6 @@
# Configure debug groups (space delimited key=value pairs, with each value comma-delimited) and default group when DEBUG=yes # Configure debug groups (space delimited key=value pairs, with each value comma-delimited) and default group when DEBUG=yes
DEBUG_GROUPS="kodi=kodi,kodi-platform,p8-platform,!mesa" DEBUG_GROUPS="kodi=kodi,kodi-platform,p8-platform,!mesa"
DEBUG_GROUP_YES="kodi" DEBUG_GROUP_YES="kodi"
# Default supported get handlers (archive, git, file etc.)
GET_HANDLER_SUPPORT="archive"

View File

@ -20,12 +20,6 @@
. config/options $1 . config/options $1
_get_file_already_downloaded() {
[ ! -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
return 0
}
if [ -z "$1" ]; then if [ -z "$1" ]; then
for i in `find packages/ -type f -name package.mk`; do for i in `find packages/ -type f -name package.mk`; do
GET_PKG=`grep ^PKG_NAME= $i | sed -e "s,\",,g" -e "s,PKG_NAME=,,"` GET_PKG=`grep ^PKG_NAME= $i | sed -e "s,\",,g" -e "s,PKG_NAME=,,"`
@ -33,63 +27,44 @@ if [ -z "$1" ]; then
done done
fi fi
[ -z "$PKG_URL" -o -z "$PKG_SOURCE_NAME" ] && exit 0 # Avoid concurrent processing of the same package
function lock_source_dir() {
mkdir -p $SOURCES/$1 local _isblocked=N
exec 99<$SOURCES/$1
PACKAGE="$SOURCES/$1/$PKG_SOURCE_NAME" while ! flock --nonblock --exclusive 99; do
PACKAGE_MIRROR="$DISTRO_MIRROR/$PKG_NAME/$PKG_SOURCE_NAME" [ ${_isblocked} == N ] && { echo "Project/Device ${DEVICE:-${PROJECT}} waiting, to avoid concurrent processing of ${1}..."; _isblocked=Y; }
[ "$VERBOSE" != "yes" ] && WGET_OPT=-q sleep 1
WGET_CMD="wget --timeout=30 --tries=3 --passive-ftp --no-check-certificate -c $WGET_OPT -O $PACKAGE"
STAMP_URL="$PACKAGE.url"
STAMP_SHA="$PACKAGE.sha256"
# Latest file already present, exit now...
_get_file_already_downloaded $1 && exit 0
# Avoid concurrent downloads of the same package
_isblocked=N
exec 99<$SOURCES/$1
while ! flock --nonblock --exclusive 99; do
[ ${_isblocked} == N ] && { echo "Project/Device ${DEVICE:-${PROJECT}} waiting, to avoid concurrent download of ${1}..."; _isblocked=Y; }
sleep 1
done
# Check again in case of concurrent access - if nothing needs to be downloaded, exit now...
_get_file_already_downloaded $1 && exit 0
# At this point, we need to download something...
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GET") $1\n" ' '>&$SILENT_OUT
export BUILD_INDENT=$((${BUILD_INDENT:-1}+$BUILD_INDENT_SIZE))
# 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
rm -f $STAMP_URL $STAMP_SHA
NBWGET=10
while [ $NBWGET -gt 0 ]; do
for url in "$PKG_URL" "$PACKAGE_MIRROR"; do
rm -f $PACKAGE
if $WGET_CMD "$url"; then
CALC_SHA256="$(sha256sum $PACKAGE | cut -d" " -f1)"
[ -z "${PKG_SHA256}" -o "${PKG_SHA256}" == "${CALC_SHA256}" ] && break 2
printf "%${BUILD_INDENT}c $(print_color CLR_WARNING "WARNING") Incorrect checksum calculated on downloaded file: got ${CALC_SHA256}, wanted ${PKG_SHA256}\n\n" ' '>&$SILENT_OUT
fi
done done
NBWGET=$((NBWGET - 1)) }
done
if [ $NBWGET -eq 0 ]; then if [ -n "$PKG_URL" -a -n "$PKG_SOURCE_NAME" ]; then
echo -e "\nCant't get $1 sources : $PKG_URL\n Try later !!" mkdir -p $SOURCES/$1
exit 1
else PACKAGE="$SOURCES/$1/$PKG_SOURCE_NAME"
printf "%${BUILD_INDENT}c $(print_color CLR_INFO "INFO") Calculated checksum: ${CALC_SHA256}\n\n" ' '>&$SILENT_OUT
echo "${PKG_URL}" > $STAMP_URL STAMP_URL="$PACKAGE.url"
echo "${CALC_SHA256}" > $STAMP_SHA STAMP_SHA="$PACKAGE.sha256"
# determine get handler based on protocol and/or filename
case "${PKG_URL}" in
git://*|*.git)
get_handler="git";;
*)
get_handler="archive";;
esac
if ! listcontains "${GET_HANDLER_SUPPORT}" "${get_handler}"; then
echo "ERROR: get handler \"${get_handler}\" is not supported, unable to get package $1 - aborting!"
exit 1
else
get_handler="${SCRIPTS}/get_${get_handler}"
if [ ! -f ${get_handler} ]; then
echo "ERROR: get handler \"${get_handler}\" does not exist, unable to get package $1 - aborting!"
exit 1
else
source ${get_handler}
fi
fi
fi fi
exit 0 exit 0

68
scripts/get_archive Executable file
View File

@ -0,0 +1,68 @@
################################################################################
# This file is part of LibreELEC - https://libreelec.tv
# Copyright (C) 2018-present Team LibreELEC
#
# LibreELEC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# LibreELEC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LibreELEC. If not, see <http://www.gnu.org/licenses/>.
################################################################################
_get_file_already_downloaded() {
[ ! -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
return 0
}
# Latest file already present, exit now...
_get_file_already_downloaded && exit 0
lock_source_dir $1
# 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...
printf "%${BUILD_INDENT}c $(print_color CLR_GET "GET") $1 (archive)\n" ' '>&$SILENT_OUT
export BUILD_INDENT=$((${BUILD_INDENT:-1}+$BUILD_INDENT_SIZE))
PACKAGE_MIRROR="$DISTRO_MIRROR/$PKG_NAME/$PKG_SOURCE_NAME"
[ "$VERBOSE" != "yes" ] && WGET_OPT=-q
WGET_CMD="wget --timeout=30 --tries=3 --passive-ftp --no-check-certificate -c $WGET_OPT -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
rm -f $STAMP_URL $STAMP_SHA
NBWGET=10
while [ $NBWGET -gt 0 ]; do
for url in "$PKG_URL" "$PACKAGE_MIRROR"; do
rm -f $PACKAGE
if $WGET_CMD "$url"; then
CALC_SHA256="$(sha256sum $PACKAGE | cut -d" " -f1)"
[ -z "${PKG_SHA256}" -o "${PKG_SHA256}" == "${CALC_SHA256}" ] && break 2
printf "%${BUILD_INDENT}c $(print_color CLR_WARNING "WARNING") Incorrect checksum calculated on downloaded file: got ${CALC_SHA256}, wanted ${PKG_SHA256}\n\n" ' '>&$SILENT_OUT
fi
done
NBWGET=$((NBWGET - 1))
done
if [ $NBWGET -eq 0 ]; then
echo -e "\nCant't get $1 sources : $PKG_URL\n Try later !!"
exit 1
else
printf "%${BUILD_INDENT}c $(print_color CLR_INFO "INFO") Calculated checksum: ${CALC_SHA256}\n\n" ' '>&$SILENT_OUT
echo "${PKG_URL}" > $STAMP_URL
echo "${CALC_SHA256}" > $STAMP_SHA
fi