Skip to content

Commit

Permalink
Merge pull request #3697 from HiassofT/le92-bumpscripts
Browse files Browse the repository at this point in the history
[le92] cleanup and improve addon update scripts
  • Loading branch information
CvH authored Jul 16, 2019
2 parents e520438 + d40e6da commit af21cb6
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 187 deletions.
127 changes: 97 additions & 30 deletions tools/mkpkg/update_binary-addons
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,50 @@
# Copyright (C) 2009-2016 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2018-present Team LibreELEC (https://libreelec.tv)

if [ -z "$1" ]; then
echo "Usage: $0 <branch-name>"
exit 0
BUMP_PKG_REV=""
KEEP_GIT_DIRS="yes"

usage() {
echo "Usage: $0 [options] <branch-name>"
echo " -b, --bump-pkg-rev: bump PKG_REV if package was not updated"
echo " -d, --delete-git-dirs: delete cloned git dirs after update"
echo " -h, --help: display help and exit"
exit 1
}

while [ $# -ne 0 ]; do
case "$1" in
-b|--bump-pkg-rev)
BUMP_PKG_REV="yes"
shift
;;
-d|--delete-git-dirs)
KEEP_GIT_DIRS=""
shift
;;
-h|--help)
usage
exit 1
;;
-*)
echo "illegal option $1"
usage
exit 1
;;
*)
break
;;
esac
done

if [ $# -ne 1 ]; then
usage
exit 1
fi

# list of packages to exclude from update
EXCLUDED_PACKAGES="vfs.nfs vfs.sacd"

# the following environment variables can be set to "yes" to enable optional features:
# KEEP_GIT_DIRS: don't delete cloned git directories after update check
# BUMP_PKG_REV: bump PKG_REV if PKG_VERSION has changed

MY_DIR="$(dirname "$0")"
ROOT="$(cd "${MY_DIR}"/../.. && pwd)"
TMPDIR="$(pwd)/.update-binary-addons-tmp"
Expand All @@ -26,24 +58,22 @@ rm -rf "${TMPDIR}"
mkdir -p "${TMPDIR}"

KODI_BRANCH="$1"
KODI_DIR="kodi-${KODI_BRANCH}.git"
KODI_DIR="kodi.git"

. "${MY_DIR}/update_common_functions"

if [ ! -d ${KODI_DIR} ] ; then
git_clone https://github.com/xbmc/xbmc ${KODI_BRANCH} ${KODI_DIR}
fi
git_clone https://github.com/xbmc/xbmc ${KODI_DIR} ${KODI_BRANCH}

# kodi-platform
# kodi-platform, points to repo+githash
REPO=$(cat $KODI_DIR/cmake/addons/depends/common/kodi-platform/kodi-platform.txt | awk '{print $2}')
GIT_HASH=$(cat $KODI_DIR/cmake/addons/depends/common/kodi-platform/kodi-platform.txt | awk '{print $3}')
PKG_NAME="kodi-platform"

git_clone $REPO master $PKG_NAME.git $GIT_HASH
git_clone $REPO $PKG_NAME.git
if [ -f "${ROOT}/packages/mediacenter/kodi-platform/package.mk" ] ; then
# update package.mk
RESOLVED_HASH=$(resolve_hash $PKG_NAME.git $GIT_HASH)
update_pkg "${ROOT}/packages/mediacenter/kodi-platform" ${PKG_NAME} ${RESOLVED_HASH}
update_pkg "${ROOT}/packages/mediacenter/kodi-platform" ${PKG_NAME} ${RESOLVED_HASH} || true
fi
if [ "${KEEP_GIT_DIRS}" != "yes" ]; then
rm -rf $PKG_NAME.git
Expand All @@ -52,30 +82,60 @@ fi
# addons
for addontxt in $KODI_DIR/cmake/addons/bootstrap/repositories/*-addons.txt ; do
ADDONS=$(cat $addontxt | awk '{print $1}')
ADDONREPO=$(cat $addontxt | awk '{print $2}')
GIT_HASH=$(cat $addontxt | awk '{print $3}')
git_clone $ADDONREPO ${KODI_BRANCH} $ADDONS.git $GIT_HASH
for addon in $ADDONS.git/*.*/ ; do
ADDONS_GIT_DIR="${ADDONS}.git"
ADDONS_GIT_REPO=$(cat $addontxt | awk '{print $2}')
ADDONS_GIT_BRANCH=$(cat $addontxt | awk '{print $3}')
git_clone $ADDONS_GIT_REPO $ADDONS_GIT_DIR ${ADDONS_GIT_BRANCH}

for addon in $ADDONS_GIT_DIR/*.*/ ; do
ADDON=$(basename $addon)

[[ ${ADDON} =~ ^game.* ]] && continue # ignore game.* addons - handled by update_retroplayer-addons

check_package_excluded "${ADDON}" "${EXCLUDED_PACKAGES}" && continue

REPO=$(cat $addon/$ADDON.txt | awk '{print $2}')
GIT_HASH=$(cat $addon/$ADDON.txt | awk '{print $3}')
GIT_DIR="${ADDON}.git"
GIT_REPO=$(cat ${addon}/${ADDON}.txt | awk '{print $2}')
GIT_BRANCH=$(cat ${addon}/${ADDON}.txt | awk '{print $3}')

if ! grep -q all $addon/platforms.txt && ! grep -q linux $addon/platforms.txt && ! grep -q ! $addon/platforms.txt; then
if ! grep -q all ${addon}/platforms.txt && ! grep -q linux ${addon}/platforms.txt && ! grep -q ! ${addon}/platforms.txt; then
continue
fi

ADDON_PATH="${ROOT}/packages/mediacenter/kodi-binary-addons/$ADDON/"
ADDON_PATH="${ROOT}/packages/mediacenter/kodi-binary-addons/${ADDON}/"
if [ -f "${ADDON_PATH}/package.mk" ] ; then
# Verify the Kodi repo matches our package repo
# If different, ignore the addon and process it later as an "unofficial" addon
validate_pkg_url "$ADDON" "$REPO" || continue

update_to_latest_tag "${ADDON_PATH}" ${ADDON} ${REPO} ${KODI_BRANCH} ${GIT_HASH}
validate_pkg_url "${ADDON}" "${GIT_REPO}" || continue

git_clone ${GIT_REPO} ${GIT_DIR} ${GIT_BRANCH}

NO_TAG=""
NEW_VERSION=$(resolve_tag_in_branch ${GIT_DIR} ${GIT_BRANCH})
if [ -z "${NEW_VERSION}" ]; then
NO_TAG="yes"
echo "========================================================================"
msg_warn "WARNING: no tag found for addon ${ADDON}, falling back to HEAD"
echo "========================================================================"
NEW_VERSION=$(resolve_hash_in_branch "${GIT_DIR}" "${GIT_BRANCH}")
fi

echo "Resolved version for ${ADDON}: ${GIT_BRANCH} => ${NEW_VERSION}"

if update_pkg "${ADDON_PATH}" ${ADDON} ${NEW_VERSION}; then
if [ -n "${NO_TAG}" ]; then
# always bump PKG_REV on updates as we have no info if version changed
bump_pkg_rev "${ADDON_PATH}" "${ADDON}"
else
reset_pkg_rev "${ADDON_PATH}" "${ADDON}"
fi
else
[ "${BUMP_PKG_REV}" = "yes" ] && bump_pkg_rev "${ADDON_PATH}" "${ADDON}"
fi

if [ "${KEEP_GIT_DIRS}" != "yes" ]; then
rm -rf "${GIT_DIR}"
fi
else
echo "[mkpkg] Skipped $ADDON"
SKIPPED_ADDONS="$SKIPPED_ADDONS $ADDON"
Expand All @@ -98,18 +158,25 @@ for ADDON in $(ls -1 "${ROOT}/packages/mediacenter/kodi-binary-addons"); do

check_package_excluded "${ADDON}" "${EXCLUDED_PACKAGES}" && continue

ADDON_PATH="${ROOT}/packages/mediacenter/kodi-binary-addons/${ADDON}/"
# Obtain git url - ignore if not a suitable repo
REPO="$(geturl "${ADDON}")" || continue
GIT_DIR="${ADDON}.git"
GIT_REPO="$(geturl "${ADDON}")" || continue

git_clone $REPO ${KODI_BRANCH} $ADDON.git HEAD
git_clone ${GIT_REPO} ${GIT_DIR}

# update package.mk for stale github.com packages
RESOLVED_HASH=$(resolve_hash ${ADDON}.git HEAD) || continue
RESOLVED_HASH=$(resolve_hash_in_branch ${ADDON}.git HEAD) || continue
echo "Resolving hash for ${ADDON}: HEAD => ${RESOLVED_HASH}"
update_pkg "${ROOT}/packages/mediacenter/kodi-binary-addons/$ADDON" ${ADDON} ${RESOLVED_HASH}
if update_pkg "${ADDON_PATH}" "${ADDON}" "${RESOLVED_HASH}"; then
# always bump PKG_REV when updating untagged addons
bump_pkg_rev "${ADDON_PATH}" "${ADDON}"
else
[ "${BUMP_PKG_REV}" = "yes" ] && bump_pkg_rev "${ADDON_PATH}" "${ADDON}"
fi

if [ "${KEEP_GIT_DIRS}" != "yes" ]; then
rm -rf $ADDON.git
rm -rf ${GIT_DIR}
fi
done

Expand Down
81 changes: 31 additions & 50 deletions tools/mkpkg/update_common_functions
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,18 @@ msg_info() {
}

git_clone() {
# git_clone https://repo.url branch ./target_dir [githash]
# git_clone https://repo.url target_dir [branch]
echo "[mkpkg] Checking out $1 ..."
if [ ! -d "$3" ]; then
git clone "$1" "$3"
# Try to switch to specified branch if it exist, if not then use default branch
if [ -n "$2" ]; then
cd "$3"
git checkout $2 >/dev/null 2>/dev/null
cd ..
fi
if [ ! -d "$2" ]; then
git clone "$1" "$2"
else
if [ -d "$3" ] ; then
cd "$3"
git checkout $2 >/dev/null 2>/dev/null
git pull
cd ..
fi
cd "$2"
git fetch
cd ..
fi

if [ ! -z "$4" ] ; then
cd "$3"
git fetch >/dev/null 2>/dev/null
git branch -D $4 >/dev/null 2>/dev/null
git checkout $4 >/dev/null 2>/dev/null
git checkout -b ref-$4 >/dev/null 2>/dev/null
if [ -n "$3" ]; then
cd "$2"
git checkout -q origin/"$3";
cd ..
fi
}
Expand All @@ -66,10 +53,17 @@ resolve_hash() {
fi
}

resolve_tag() {
resolve_hash_in_branch() {
if [ -d "$1" ] ; then
cd "$1"
git rev-parse origin/$2 2>/dev/null
fi
}

resolve_tag_in_branch() {
if [ -d "$1" ] ; then
cd "$1"
git describe --abbrev=0 --tags $2 2>/dev/null
git describe --abbrev=0 --tags origin/$2 2>/dev/null
fi
}

Expand Down Expand Up @@ -118,6 +112,15 @@ bump_pkg_rev() {
msg_info "BUMPED ${pkg_name} PKG_REV from ${pkg_rev} to ${new_pkg_rev}"
}

reset_pkg_rev() {
local package_mk="$1/package.mk" pkg_name="$2"
local pkg_rev=$(get_pkg_var "${pkg_name}" PKG_REV)
local new_pkg_rev="1"

sed -e "s|PKG_REV=.*|PKG_REV=\"${new_pkg_rev}\"|" -i "${package_mk}"
msg_info "RESET ${pkg_name} PKG_REV from ${pkg_rev} to ${new_pkg_rev}"
}

update_pkg() {
local pkg_path="$1" pkg_name="$2" pkg_version="$3"

Expand All @@ -131,33 +134,11 @@ update_pkg() {
download_pkg_file "${pkg_name}"
set_pkg_sha256 "${pkg_path}"

if [ "${BUMP_PKG_REV}" = "yes" ]; then
bump_pkg_rev "${pkg_path}" "${pkg_name}"
fi
fi
}

update_to_latest_tag() {
local pkg_path="$1" pkg_name="$2" repo="$3" branch="$4" ref="$5"
local gitdir=${pkg_name}.git
local resolved_version

git_clone "${repo}" "${branch}" "${gitdir}" "${ref}"
msg_info "UPDATED ${pkg_name} from ${old_version} to ${pkg_version}"

resolved_version=$(resolve_tag "${gitdir}" "${ref}")
if [ -z "${resolved_version}" ]; then
echo "========================================================================"
msg_warn "WARNING: no tag found for package ${pkg_name}, falling back to HEAD"
echo "========================================================================"
resolved_version=$(resolve_hash "${gitdir}" "${ref}")
fi

echo "Resolved version for ${pkg_name}: ${ref} => ${resolved_version}"

update_pkg "${pkg_path}" "${pkg_name}" "${resolved_version}"

if [ "${KEEP_GIT_DIRS}" != "yes" ]; then
rm -rf "${gitdir}"
return 0
else
return 1
fi
}

Expand Down
Loading

0 comments on commit af21cb6

Please sign in to comment.