refactor(auto-update): clean up some code

- move epoch addition to termux_pkg_upgrade_version set.
- now termux_pkg_upgrade_version can be given retrived version/tag from
  api, directly.

Signed-off-by: Aditya Alok <dev.aditya.alok@gmail.com>
This commit is contained in:
Aditya Alok 2022-04-05 11:12:51 +05:30
parent 891932b344
commit d67a38d324
No known key found for this signature in database
GPG Key ID: 5A52117417798AC7
4 changed files with 19 additions and 55 deletions

View File

@ -1,18 +1,6 @@
# shellcheck shell=bash
# Default algorithm to use for packages hosted on github.com
termux_github_auto_update() {
local pkg_version
pkg_version="$(echo "${TERMUX_PKG_VERSION}" | cut -d: -f2-)"
local pkg_epoch
pkg_epoch="$(echo "${TERMUX_PKG_VERSION}" | cut -d: -f1)"
if [[ "${pkg_version}" == "${pkg_epoch}" ]]; then
# No epoch set.
pkg_epoch=""
else
pkg_epoch+=":"
fi
local latest_tag
latest_tag="$(
termux_github_api_get_tag "${TERMUX_PKG_SRCURL}" "${TERMUX_PKG_UPDATE_TAG_TYPE}"
@ -21,5 +9,5 @@ termux_github_auto_update() {
if [[ -z "${latest_tag}" ]]; then
termux_error_exit "ERROR: Unable to get tag from ${TERMUX_PKG_SRCURL}"
fi
termux_pkg_upgrade_version "${pkg_epoch}${latest_tag}"
termux_pkg_upgrade_version "${latest_tag}"
}

View File

@ -1,19 +1,6 @@
# shellcheck shell=bash
# Default algorithm to use for packages hosted on hosts using gitlab-ci.
termux_gitlab_auto_update() {
# Our local version of package.
local pkg_version
pkg_version="$(echo "${TERMUX_PKG_VERSION}" | cut -d: -f2-)"
local pkg_epoch
pkg_epoch="$(echo "${TERMUX_PKG_VERSION}" | cut -d: -f1)"
if [[ "${pkg_version}" == "${pkg_epoch}" ]]; then
# No epoch set.
pkg_epoch=""
else
pkg_epoch+=":"
fi
local latest_tag
latest_tag="$(
termux_gitlab_api_get_tag \
@ -24,5 +11,5 @@ termux_gitlab_auto_update() {
if [[ -z "${latest_tag}" ]]; then
termux_error_exit "ERROR: Unable to get tag from ${TERMUX_PKG_SRCURL}"
fi
termux_pkg_upgrade_version "${pkg_epoch}${latest_tag}"
termux_pkg_upgrade_version "${latest_tag}"
}

View File

@ -1,26 +1,12 @@
# shellcheck shell=bash
termux_repology_auto_update() {
# Our local version of package.
local pkg_version
pkg_version="$(echo "${TERMUX_PKG_VERSION}" | cut -d: -f2-)"
local pkg_epoch
pkg_epoch="$(echo "${TERMUX_PKG_VERSION}" | cut -d: -f1)"
if [[ "${pkg_version}" == "${pkg_epoch}" ]]; then
# No epoch set.
pkg_epoch=""
else
pkg_epoch+=":"
fi
local latest_version
latest_version="$(termux_repology_api_get_latest_version "${TERMUX_PKG_NAME}")"
# Repology api returns null if package is not tracked by repology or is already upto date.
if [[ "${latest_version}" == "null" ]]; then
echo "INFO: Already up to date." # Since we exclude unique to termux packages, this package
# should be tracked by repology and be already up to date.
echo "INFO: Already up to date." # Since we exclude unique to termux packages from auto-update,
# this package should be tracked by repology and be already up to date.
return 0
fi
termux_pkg_upgrade_version "${pkg_epoch}${latest_version}"
termux_pkg_upgrade_version "${latest_version}"
}

View File

@ -4,7 +4,6 @@ termux_pkg_upgrade_version() {
# Show usage.
termux_error_exit <<-EndUsage
Usage: ${FUNCNAME[0]} LATEST_VERSION [--skip-version-check]
Version should be passed with epoch, if any.
EndUsage
fi
@ -13,11 +12,18 @@ termux_pkg_upgrade_version() {
local PKG_DIR
PKG_DIR="${TERMUX_SCRIPTDIR}/packages/${TERMUX_PKG_NAME}"
local EPOCH
EPOCH="${TERMUX_PKG_VERSION%%:*}" # If there is no epoch, this will be the full version.
# Check if it isn't the full version and add ':'.
if [[ "${EPOCH}" != "${TERMUX_PKG_VERSION}" ]]; then
EPOCH="${EPOCH}:"
else
EPOCH=""
fi
# If needed, filter version numbers using regexp.
if [[ -n "${TERMUX_PKG_UPDATE_VERSION_REGEXP}" ]]; then
# Before extracting version numbers, seperate epoch if present.
local EPOCH
EPOCH="${LATEST_VERSION%%:*}"
# Extract version numbers.
LATEST_VERSION="$(grep -oP "${TERMUX_PKG_UPDATE_VERSION_REGEXP}" <<<"${LATEST_VERSION}" || true)"
if [[ -z "${LATEST_VERSION}" ]]; then
termux_error_exit <<-EndOfError
@ -25,9 +31,6 @@ termux_pkg_upgrade_version() {
Ensure that it is works correctly with ${LATEST_VERSION}.
EndOfError
fi
if [[ -n "${EPOCH}" ]]; then
LATEST_VERSION="${EPOCH}:${LATEST_VERSION}"
fi
fi
# Translate "_" into ".": some packages use underscores to seperate
@ -43,12 +46,12 @@ termux_pkg_upgrade_version() {
fi
if [[ "${BUILD_PACKAGES}" == "false" ]]; then
echo "INFO: package needs to be updated to ${LATEST_VERSION#*:}."
echo "INFO: package needs to be updated to ${LATEST_VERSION}."
else
echo "INFO: package being updated to ${LATEST_VERSION#*:}."
echo "INFO: package being updated to ${LATEST_VERSION}."
sed -i \
"s/^\(TERMUX_PKG_VERSION=\)\(.*\)\$/\1\"${LATEST_VERSION}\"/g" \
"s/^\(TERMUX_PKG_VERSION=\)\(.*\)\$/\1\"${EPOCH}${LATEST_VERSION}\"/g" \
"${PKG_DIR}/build.sh"
sed -i \
"/TERMUX_PKG_REVISION=/d" \
@ -69,7 +72,7 @@ termux_pkg_upgrade_version() {
echo "INFO: Committing package."
stderr="$(
git add "${PKG_DIR}" 2>&1 >/dev/null
git commit -m "${TERMUX_PKG_NAME}: update to ${LATEST_VERSION#*:}" \
git commit -m "${TERMUX_PKG_NAME}: update to ${LATEST_VERSION}" \
-m "This commit has been automatically submitted by Github Actions." 2>&1 >/dev/null
)" || {
termux_error_exit <<-EndOfError