Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(termux_pkg_upgrade_version): some fixes #22054

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 78 additions & 61 deletions scripts/updates/utils/termux_pkg_upgrade_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,70 +63,87 @@ termux_pkg_upgrade_version() {

if [[ "${BUILD_PACKAGES}" == "false" ]]; then
echo "INFO: package needs to be updated to ${LATEST_VERSION}."
else
echo "INFO: package being updated to ${LATEST_VERSION}."

sed -i \
"s/^\(TERMUX_PKG_VERSION=\)\(.*\)\$/\1\"${EPOCH}${LATEST_VERSION}\"/g" \
"${TERMUX_PKG_BUILDER_DIR}/build.sh"
sed -i \
"/TERMUX_PKG_REVISION=/d" \
"${TERMUX_PKG_BUILDER_DIR}/build.sh"

# Update checksum
if [[ "${TERMUX_PKG_SHA256[*]}" != "SKIP_CHECKSUM" ]] && [[ "${TERMUX_PKG_SRCURL:0:4}" != "git+" ]]; then
echo n | "${TERMUX_SCRIPTDIR}/scripts/bin/update-checksum" "${TERMUX_PKG_NAME}" || {
git checkout -- "${TERMUX_PKG_BUILDER_DIR}"
git pull --rebase
termux_error_exit "ERROR: failed to update checksum."
}
fi
return
fi

echo "INFO: Trying to build package."

for repo_path in $(jq --raw-output 'del(.pkg_format) | keys | .[]' ${TERMUX_SCRIPTDIR}/repo.json); do
_buildsh_path="${TERMUX_SCRIPTDIR}/${repo_path}/${TERMUX_PKG_NAME}/build.sh"
repo=$(jq --raw-output ".\"${repo_path}\".name" ${TERMUX_SCRIPTDIR}/repo.json)
repo=${repo#"termux-"}

if [ -f "${_buildsh_path}" ]; then
echo "INFO: Package ${TERMUX_PKG_NAME} exists in ${repo} repo."
unset _buildsh_path repo_path
break
fi
done

if "${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./build-package.sh -a "${TERMUX_ARCH}" -i "${TERMUX_PKG_NAME}"; then
if [[ "${GIT_COMMIT_PACKAGES}" == "true" ]]; then
echo "INFO: Committing package."
stderr="$(
git add "${TERMUX_PKG_BUILDER_DIR}" 2>&1 >/dev/null
git commit -m "bump(${repo}/${TERMUX_PKG_NAME}): ${LATEST_VERSION}" \
-m "This commit has been automatically submitted by Github Actions." 2>&1 >/dev/null
)" || {
termux_error_exit <<-EndOfError
ERROR: git commit failed. See below for details.
${stderr}
EndOfError
}
fi

if [[ "${GIT_PUSH_PACKAGES}" == "true" ]]; then
echo "INFO: Pushing package."
stderr="$(
git pull --rebase 2>&1 >/dev/null
git push 2>&1 >/dev/null
)" || {
termux_error_exit <<-EndOfError
ERROR: git push failed. See below for details.
${stderr}
EndOfError
}
fi
else
echo "INFO: package being updated to ${LATEST_VERSION}."

sed \
-e "s/^\(TERMUX_PKG_VERSION=\)\(.*\)\$/\1\"${EPOCH}${LATEST_VERSION}\"/g" \
-e "/TERMUX_PKG_REVISION=/d" \
-i "${TERMUX_PKG_BUILDER_DIR}/build.sh"

# Update checksum
if [[ "${TERMUX_PKG_SHA256[*]}" != "SKIP_CHECKSUM" ]] && [[ "${TERMUX_PKG_SRCURL:0:4}" != "git+" ]]; then
echo n | "${TERMUX_SCRIPTDIR}/scripts/bin/update-checksum" "${TERMUX_PKG_NAME}" || {
git checkout -- "${TERMUX_PKG_BUILDER_DIR}"
termux_error_exit "ERROR: failed to build."
git pull --rebase
termux_error_exit "ERROR: failed to update checksum."
}
fi

echo "INFO: Trying to build package."

for repo_path in $(jq --raw-output 'del(.pkg_format) | keys | .[]' ${TERMUX_SCRIPTDIR}/repo.json); do
_buildsh_path="${TERMUX_SCRIPTDIR}/${repo_path}/${TERMUX_PKG_NAME}/build.sh"
repo=$(jq --raw-output ".\"${repo_path}\".name" ${TERMUX_SCRIPTDIR}/repo.json)
repo=${repo#"termux-"}

if [[ -f "${_buildsh_path}" ]]; then
echo "INFO: Package ${TERMUX_PKG_NAME} exists in ${repo} repo."
unset _buildsh_path repo_path
break
fi
done

local big_package=false
while IFS= read -r p; do
if [[ "${p}" == "${TERMUX_PKG_NAME}" ]]; then
big_package=true
break
fi
done < "${TERMUX_SCRIPTDIR}/scripts/big-pkgs.list"

if [[ "${big_package}" == "true" ]]; then
"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh
fi

if ! "${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./build-package.sh -a "${TERMUX_ARCH}" -i "${TERMUX_PKG_NAME}"; then
if [[ "${big_package}" == "true" ]]; then
"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh
fi
git checkout -- "${TERMUX_PKG_BUILDER_DIR}"
termux_error_exit "ERROR: failed to build."
fi

if [[ "${big_package}" == "true" ]]; then
"${TERMUX_SCRIPTDIR}/scripts/run-docker.sh" ./clean.sh
fi

if [[ "${GIT_COMMIT_PACKAGES}" == "true" ]]; then
echo "INFO: Committing package."
stderr="$(
git add "${TERMUX_PKG_BUILDER_DIR}" 2>&1 >/dev/null
git commit -m "bump(${repo}/${TERMUX_PKG_NAME}): ${LATEST_VERSION}" \
-m "This commit has been automatically submitted by Github Actions." 2>&1 >/dev/null
)" || {
termux_error_exit <<-EndOfError
ERROR: git commit failed. See below for details.
${stderr}
EndOfError
}
fi

if [[ "${GIT_PUSH_PACKAGES}" == "true" ]]; then
echo "INFO: Pushing package."
stderr="$(
git pull --rebase 2>&1 >/dev/null
git push 2>&1 >/dev/null
)" || {
termux_error_exit <<-EndOfError
ERROR: git push failed. See below for details.
${stderr}
EndOfError
}
fi
}