fix(auto-updates): move extraction of version from regexp to upgrade version step

previously setting TERMUX_PKG_UPDATE_VERSION_REGEXP had no effect on version being wriiten to
build.sh. It was only used for version comparison.

Signed-off-by: Aditya Alok <dev.aditya.alok@gmail.com>
This commit is contained in:
Aditya Alok 2022-04-01 12:58:16 +05:30
parent 9f28b53c09
commit a7d089c195
No known key found for this signature in database
GPG Key ID: 5A52117417798AC7
2 changed files with 25 additions and 19 deletions

View File

@ -9,7 +9,7 @@
# latest lua:lpeg version (as of 2021-11-20T12:21:31) is "1.0.2" but MacPorts specifies as "1.0.2-1".
# Hence repology returns "1.0.2-1" as the latest.
#
# But hopefully, all this can be avoided if TERMUX_PKG_AUTO_UPDATE_TAG_REGEXP is set.
# But hopefully, all this can be avoided if TERMUX_PKG_UPDATE_VERSION_REGEXP is set.
#
termux_pkg_is_update_needed() {
# USAGE: termux_pkg_is_update_needed <current-version> <latest-version> [regexp]
@ -20,23 +20,6 @@ termux_pkg_is_update_needed() {
local CURRENT_VERSION="$1"
local LATEST_VERSION="$2"
local VERSION_REGEX="${3:-}"
# If needed, filter version numbers from tag by using regexp.
if [[ -n "${VERSION_REGEX}" ]]; then
LATEST_VERSION="$(grep -oP "${VERSION_REGEX}" <<<"${LATEST_VERSION}" || true)"
if [[ -z "${LATEST_VERSION}" ]]; then
termux_error_exit <<-EndOfError
ERROR: failed to compare versions. Ensure whether the version regex '${VERSION_REGEX}'
works correctly with given versions.
EndOfError
fi
fi
# Translate "_" into ".": some packages use underscores to seperate
# version numbers, but we require them to be separated by dots.
LATEST_VERSION="${LATEST_VERSION//_/.}"
# Compare versions.
# shellcheck disable=SC2091
@ -79,6 +62,13 @@ if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
first_version="$1"
second_version="$2"
version_regexp="${3:-}"
if [[ -n "${version_regexp}" ]]; then
first_version="$(grep -oP "${version_regexp}" <<<"${first_version}")"
second_version="$(grep -oP "${version_regexp}" <<<"${second_version}")"
if [[ -z "${first_version}" ]] || [[ -z "${second_version}" ]]; then
termux_error_exit "ERROR: Unable to parse version numbers using regexp '${version_regexp}'"
fi
fi
if termux_pkg_is_update_needed "${first_version}" "${second_version}" "${version_regexp}"; then
echo "${first_version} < ${second_version}"
else

View File

@ -13,9 +13,25 @@ termux_pkg_upgrade_version() {
local PKG_DIR
PKG_DIR="${TERMUX_SCRIPTDIR}/packages/${TERMUX_PKG_NAME}"
# If needed, filter version numbers using regexp.
if [[ -n "${TERMUX_PKG_UPDATE_VERSION_REGEXP}" ]]; then
LATEST_VERSION="$(grep -oP "${TERMUX_PKG_UPDATE_VERSION_REGEXP}" <<<"${LATEST_VERSION}" || true)"
if [[ -z "${LATEST_VERSION}" ]]; then
termux_error_exit <<-EndOfError
ERROR: failed to filter version numbers using regexp '${TERMUX_PKG_UPDATE_VERSION_REGEXP}'.
Ensure that it is works correctly with ${LATEST_VERSION}.
EndOfError
fi
fi
# Translate "_" into ".": some packages use underscores to seperate
# version numbers, but we require them to be separated by dots.
LATEST_VERSION="${LATEST_VERSION//_/.}"
if [[ "${SKIP_VERSION_CHECK}" != "--skip-version-check" ]]; then
if ! termux_pkg_is_update_needed \
"${TERMUX_PKG_VERSION}" "${LATEST_VERSION}" "${TERMUX_PKG_UPDATE_VERSION_REGEXP}"; then
"${TERMUX_PKG_VERSION}" "${LATEST_VERSION}"; then
echo "INFO: No update needed. Already at version '${TERMUX_PKG_VERSION}'."
return 0
fi