fix(auto update): fix few messages, comments and code

Signed-off-by: Aditya Alok <dev.aditya.alok@gmail.com>
This commit is contained in:
Aditya Alok 2022-03-27 23:38:57 +05:30
parent 3bc578adb3
commit 694a941883
6 changed files with 25 additions and 29 deletions

View File

@ -13,7 +13,7 @@ set -u
export TERMUX_PKG_UPDATE_METHOD="" # Which method to use for updating? (repology, github or gitlab)
export TERMUX_PKG_UPDATE_TAG_TYPE="" # Whether to use latest-release-tag or newest-tag.
export TERMUX_GITLAB_API_HOST="gitlab.com" # Default host for gitlab-ci.
export TERMUX_PKG_AUTO_UPDATE=true # Whether to auto-update or not.
export TERMUX_PKG_AUTO_UPDATE=false # Whether to auto-update or not. Disabled by default.
export TERMUX_PKG_UPDATE_VERSION_REGEXP="" # Regexp to extract version.
export TERMUX_REPOLOGY_DATA_FILE
TERMUX_REPOLOGY_DATA_FILE="$(mktemp -t termux-repology.XXXXXX)" # File to store repology data.
@ -59,7 +59,7 @@ TERMUX_SCRIPTDIR="$(realpath "$(dirname "$0")/../..")" # Script directory.
# shellcheck source=scripts/updates/internal/termux_gitlab_auto_update.sh
. "${TERMUX_SCRIPTDIR}"/scripts/updates/internal/termux_gitlab_auto_update.sh
# Default auto update script for packages. Should not be overrided by build.sh.
# Default auto update script for rest packages. Should not be overrided by build.sh.
# To use custom algorithm, one should override termux_pkg_auto_update().
# shellcheck source=scripts/updates/internal/termux_repology_auto_update.sh
. "${TERMUX_SCRIPTDIR}"/scripts/updates/internal/termux_repology_auto_update.sh
@ -107,15 +107,14 @@ _update() {
}
_test_pkg_build_file() {
local pkg_dir
pkg_dir="$1"
local pkg_dir="$1"
if [[ ! -f "${pkg_dir}/build.sh" ]]; then
# Fail if detected a non-package directory.
termux_error_exit "ERROR: directory '${pkg_dir}' is not a package."
fi
}
declare -a _failed_updates=()
declare -a _FAILED_UPDATES=()
_run_update() {
local pkg_dir="$1"
@ -127,7 +126,7 @@ _run_update() {
)
# shellcheck disable=SC2181
if [[ $? -ne 0 ]]; then
_failed_updates+=("$(basename "${pkg_dir}")")
_FAILED_UPDATES+=("$(basename "${pkg_dir}")")
fi
}
@ -143,12 +142,13 @@ _get_unique_packages() {
echo "${unique_packages[@]}"
}
declare -a _unique_packages
read -r -a _unique_packages <<<"$(_get_unique_packages)"
declare -a _UNIQUE_PACKAGES
read -r -a _UNIQUE_PACKAGES <<<"$(_get_unique_packages)"
_unique_to_termux() {
local pkg_dir="$1"
if [[ "${_unique_packages[*]}" =~ "$(basename "${pkg_dir}")" ]]; then
# shellcheck disable=2076 # We want literal match not regex.
if [[ "${_UNIQUE_PACKAGES[*]}" =~ "$(basename "${pkg_dir}")" ]]; then
return 0
else
return 1
@ -180,10 +180,10 @@ main() {
done
fi
if ((${#_failed_updates[@]} > 0)); then
if ((${#_FAILED_UPDATES[@]} > 0)); then
echo # Newline.
echo "===========================Failed updates==========================="
for failed_update in "${_failed_updates[@]}"; do
for failed_update in "${_FAILED_UPDATES[@]}"; do
echo "==> ${failed_update}"
done
exit 1 # Exit with error code, so that we know that some/all updates failed.

View File

@ -38,7 +38,6 @@ def get_repology_data(last_project):
def get_outdated_packages():
termux_outdated_packages = {}
last_project = ""
brk_flag = False # Flag to break the infinite loop.
while True:
repology_data = get_repology_data(last_project)
@ -48,9 +47,11 @@ def get_outdated_packages():
# Quoting repology documentation: "You may iterate through
# all projects by using the last project name in the next request"
# For more info, visit https://repology.org/api
# NOTE: next response to request will include the last_project given.
if len(repology_data) <= 1:
# Break the loop after this iteration.
brk_flag = True
# Break the loop now. Since api returned only one package, it
# must be the last_project, which was already included in previous iteration.
break
for package_name, package_data in repology_data.items():
if package_name in termux_outdated_packages:
@ -74,8 +75,6 @@ def get_outdated_packages():
else:
# If we don't find any version, skip the package.
continue
if brk_flag:
break
return termux_outdated_packages

View File

@ -30,11 +30,11 @@ termux_github_api_get_tag() {
fi
local jq_filter
local api_url=""
local api_url="https://api.github.com"
local extra_curl_opts=""
if [[ "${TAG_TYPE}" == "newest-tag" ]]; then
api_url="https://api.github.com/graphql"
api_url="${api_url}/graphql"
jq_filter='.data.repository.refs.edges[0].node.name'
extra_curl_opts="-d $(
cat <<-EOF
@ -57,7 +57,7 @@ termux_github_api_get_tag() {
EOF
)"
elif [[ "${TAG_TYPE}" == "latest-release-tag" ]]; then
api_url="${api_url}/releases/latest"
api_url="${api_url}/repos/${project}/releases/latest"
jq_filter=".tag_name"
else
termux_error_exit <<-EndOfError

View File

@ -89,8 +89,6 @@ termux_gitlab_api_get_tag() {
${response}
EndOfError
fi
elif [[ "${http_code}" == "304" ]]; then
return 2 # Up-to-date.
else
termux_error_exit <<-EndOfError
ERROR: Failed to get '${TAG_TYPE}' (${api_url}).

View File

@ -26,13 +26,13 @@ termux_pkg_is_update_needed() {
# If needed, filter version numbers from tag by using regexp.
if [[ -n "${VERSION_REGEX}" ]]; then
LATEST_VERSION="$(grep -oP "${VERSION_REGEX}" <<<"${LATEST_VERSION}" || true)"
fi
if [[ -z "${LATEST_VERSION}" ]]; then
termux_error_exit <<-EndOfError
ERROR: failed to check latest version. Ensure whether the version regex '${VERSION_REGEX}'
works correctly with latest release tag.
EndOfError
if [[ -z "${LATEST_VERSION}" ]]; then
termux_error_exit <<-EndOfError
ERROR: failed to check latest version. Ensure whether the version regex '${VERSION_REGEX}'
works correctly with latest release tag.
EndOfError
fi
fi
# Translate "_" into ".": some packages use underscores to seperate

View File

@ -27,7 +27,7 @@ termux_pkg_upgrade_version() {
echo "INFO: package being updated to $(echo "${LATEST_VERSION}" | cut -d':' -f2)."
sed -i \
"s/^\(TERMUX_PKG_VERSION=\)\(.*\)\$/\1${LATEST_VERSION}/g" \
"s/^\(TERMUX_PKG_VERSION=\)\(.*\)\$/\1\"${LATEST_VERSION}\"/g" \
"${PKG_DIR}/build.sh"
sed -i \
"/TERMUX_PKG_REVISION=/d" \
@ -61,7 +61,6 @@ termux_pkg_upgrade_version() {
if [[ "${GIT_PUSH_PACKAGES}" == "true" ]]; then
echo "INFO: Pushing package."
stderr="$(
git status # DEBUG
git pull --rebase 2>&1 >/dev/null
git push 2>&1 >/dev/null
)" || {