diff --git a/packages/manpages/build.sh b/packages/manpages/build.sh index 69c6f70cbab94b..36927dcbcedf9a 100644 --- a/packages/manpages/build.sh +++ b/packages/manpages/build.sh @@ -2,9 +2,9 @@ TERMUX_PKG_HOMEPAGE=https://www.kernel.org/doc/man-pages/ TERMUX_PKG_DESCRIPTION="Man pages for linux kernel and C library interfaces" TERMUX_PKG_LICENSE="custom" TERMUX_PKG_LICENSE_FILE="LICENSES/Linux-man-pages-copyleft.txt, _man-pages-posix/POSIX-COPYRIGHT" -TERMUX_PKG_MAINTAINER="@termux" -TERMUX_PKG_VERSION=(6.13 - 2017) +TERMUX_PKG_MAINTAINER="Joshua Kahn @TomJo2000" +TERMUX_PKG_VERSION=(6.12 # Kernel man pages + 2017) # POSIX man pages TERMUX_PKG_REVISION=1 TERMUX_PKG_SHA256=( a2c8a0c2efe8a978ce51ce800461eb9e8931f12cc7ba4b7faa3082b69ba7f12c @@ -19,6 +19,10 @@ TERMUX_PKG_PROVIDES="linux-man-pages" TERMUX_PKG_EXTRA_MAKE_ARGS="-R prefix=$TERMUX_PREFIX VERSION=$TERMUX_PKG_VERSION" TERMUX_PKG_PLATFORM_INDEPENDENT=true TERMUX_PKG_BUILD_IN_SRC=true +TERMUX_PKG_AUTO_UPDATE=true +# Man pages are only usually updated for new Kernel releases, not patch releases. +TERMUX_PKG_UPDATE_VERSION_REGEXP='\d+\.\d+' + # Do not remove an entire section; intro should always be included. # Bionic libc does not provide , or pthread_cancel. @@ -42,8 +46,30 @@ share/man/man7/man.7 share/man/man7/mdoc.7 " +termux_pkg_auto_update() { + local latest_kernel_major + latest_kernel_major="$(git ls-remote --tags https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git \ + | grep -oP "refs/tags/v\K${TERMUX_PKG_UPDATE_VERSION_REGEXP}$" \ + | sort -V \ + | tail -n1)" + + # No new major release. + if [[ "${latest_kernel_major}" == "${TERMUX_PKG_VERSION[0]}" ]]; then + echo "INFO: No update needed. Already at version '${TERMUX_PKG_VERSION[0]}'." + return + fi + + # Verify that this major updated the man pages + curl -fsSL "https://www.kernel.org/pub/linux/docs/man-pages/man-pages-${latest_kernel_major}.tar.sign" &> /dev/null || { + echo "Info: Not updating. Linux ${latest_kernel_major} doesn't seem to have updates the man pages." + } + + termux_pkg_upgrade_version "${latest_kernel_major}" +} + + termux_step_post_get_source() { - mv man-pages-posix-${TERMUX_PKG_VERSION[1]} _man-pages-posix + mv "man-pages-posix-${TERMUX_PKG_VERSION[1]}" _man-pages-posix } termux_step_make() { diff --git a/scripts/bin/update-checksum b/scripts/bin/update-checksum index 19d79754c3b4d7..bab20fdc227a3e 100755 --- a/scripts/bin/update-checksum +++ b/scripts/bin/update-checksum @@ -54,27 +54,52 @@ for package in "${@}"; do continue fi - # Command substitution create a subshell, we want to do this - # to not effect the main scope's variables by sourcing the build script - new_checksum=($( - source "${buildsh_path}" 2>/dev/null - for url in "${TERMUX_PKG_SRCURL[@]}"; do - echo "Downloading ${url}" >&2 - dl_tmpdir=$(mktemp -d "${TMPDIR-/tmp}/termux.src.dl.XXXXXXXX") + ( + function get_sha256() { + local dl_tmpdir + for url in "$@"; do + echo "Downloading ${url}" >&2 + dl_tmpdir="$(mktemp -d "${TMPDIR-/tmp}/termux.src.dl.XXXXXXXX")" + + if [[ -d "${dl_tmpdir}" ]]; then + if ! curl --fail --location --retry 3 --output "${dl_tmpdir}/source-bundle" "$url"; then + rm -rf "${dl_tmpdir}" + fi + + if [[ -f "${dl_tmpdir}/source-bundle" ]]; then + sha256sum "${dl_tmpdir}/source-bundle" | awk '{ print $1 }' + fi - if [[ -d "${dl_tmpdir}" ]]; then - if ! curl --fail --location --retry 3 --output "${dl_tmpdir}/source-bundle" "$url"; then rm -rf "${dl_tmpdir}" fi + done + } - if [[ -f "${dl_tmpdir}/source-bundle" ]]; then - sha256sum "${dl_tmpdir}/source-bundle" | awk '{ print $1 }' - fi + # shellcheck source=/dev/null + source "${buildsh_path}" 2>/dev/null + source "$REPO_ROOT/scripts/updates/utils/termux_pkg_patch_value.sh" - rm -rf "${dl_tmpdir}" - fi - done - )) + old_checksum='' + new_checksum='' + case "${TERMUX_PKG_SRCURL@a}" in + 'a') { + for (( i = 0; i < ${#TERMUX_PKG_SRCURL[*]}; i++ )); do + old_checksum="${TERMUX_PKG_SHA256[$i]}" + new_checksum="$(get_sha256 "${TERMUX_PKG_SRCURL[$i]}")" + termux_pkg_patch_value 'TERMUX_PKG_SHA256' \ + "$old_checksum" "$new_checksum" "$buildsh_path" + done + } > "${TMPDIR-/tmp}/${package}.auto.patch" + ;; + '') { + old_checksum="${TERMUX_PKG_SHA256}" + new_checksum="$(get_sha256 "${TERMUX_PKG_SRCURL}")" + termux_pkg_patch_value 'TERMUX_PKG_SHA256' \ + "$old_checksum" "$new_checksum" "$buildsh_path" + } > "${TMPDIR-/tmp}/${package}.auto.patch" + ;; + esac + ) if (( ${#new_checksum[@]} )); then # Replace old SHA-256. diff --git a/scripts/updates/utils/termux_pkg_patch_value.sh b/scripts/updates/utils/termux_pkg_patch_value.sh new file mode 100644 index 00000000000000..b8d6c6151b84d0 --- /dev/null +++ b/scripts/updates/utils/termux_pkg_patch_value.sh @@ -0,0 +1,28 @@ +#!/bin/false +# This script should be sourced, not run standalone. + +# shellcheck shell=bash +# $1 - What variable are we patching? +# $2 - Old value to replace +# $3 - New value to substitute +# $4 - File to patch +termux_pkg_patch_value() { + local target_value="$1" + local old_value="$2" + local new_value="$3" + local file_path="$4" + + local regex + case "$target_value" in + 'TERMUX_PKG_VERSION') regex='(?m)^\s*TERMUX_PKG_VERSION[^=]*=(?:[^\(\n]*$|\((?:[^\)]*\))+?(?=\s*#|$))';; + 'TERMUX_PKG_SHA256') regex='(?m)^\s*TERMUX_PKG_SHA256[^=]*=(?:[^\(\n]*$|\((?:[^\)]*\))+?(?=\s*#|$))';; + *) return 1;; + esac + + local match + match="$(grep -bzoP "${regex}" "${file_path}")" + git -P diff --ignore-space-at-eol --text --no-index \ + <(tail -c+$(( ${match%:*} + 1 )) "${file_path}" | head -c${#match#*:}) \ + <(sed -e "s/${old_value}/${new_value}/;s/\x0//" <<< "${match#*:}") \ + | sed -e "s@proc/self/fd/[0-9]*@${file_path}@g" +} diff --git a/scripts/updates/utils/termux_pkg_upgrade_version.sh b/scripts/updates/utils/termux_pkg_upgrade_version.sh index c4ab484cd68466..07a79e20441af7 100755 --- a/scripts/updates/utils/termux_pkg_upgrade_version.sh +++ b/scripts/updates/utils/termux_pkg_upgrade_version.sh @@ -84,8 +84,8 @@ termux_pkg_upgrade_version() { echo "INFO: package being updated to ${LATEST_VERSION}." - sed \ - -e "s/^\(TERMUX_PKG_VERSION=\)\(.*\)\$/\1\"${EPOCH}${LATEST_VERSION}\"/g" \ + sed -r \ + -e "s/^(TERMUX_PKG_VERSION=\(?)(.*)\$/\1\"${EPOCH}${LATEST_VERSION}\"/g" \ -e "/TERMUX_PKG_REVISION=/d" \ -i "${TERMUX_PKG_BUILDER_DIR}/build.sh"