Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src/lib/util/pkgbuild.sh
diff options
context:
space:
mode:
authorLevente Polyak <anthraxx@archlinux.org>2024-04-19 21:16:06 +0200
committerLevente Polyak <anthraxx@archlinux.org>2024-04-23 20:23:49 +0200
commit9a5181db5bfa78d33d3123145ea4c84375f2e8f2 (patch)
tree0fa37ffd91753cb57368eb7d4546fa0aeeead82c /src/lib/util/pkgbuild.sh
parent55c2ca1312e649916a9a4469b7e88464f2f20c38 (diff)
feat(pkgctl): add internal update checksums to better control output
This allows us to have more control over the output and status logs. Using this method we are able to avoid cluttering the version upgrade subcommand while downloading sources for updating the checksums. Having this internally will also allow us in the future to have smart checksums updating by only trying to change the checksums of sources that have actually changed, for example when adjusting a patch file we should avoid trying to overwrite the archive checksums unintentionally. Component: pkgctl version upgrade
Diffstat (limited to 'src/lib/util/pkgbuild.sh')
-rw-r--r--src/lib/util/pkgbuild.sh50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/lib/util/pkgbuild.sh b/src/lib/util/pkgbuild.sh
index ebf8e5f..245a82f 100644
--- a/src/lib/util/pkgbuild.sh
+++ b/src/lib/util/pkgbuild.sh
@@ -6,10 +6,13 @@
DEVTOOLS_INCLUDE_UTIL_PKGBUILD_SH=1
_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
+# shellcheck source=src/lib/util/makepkg.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/makepkg.sh
source /usr/share/makepkg/util/message.sh
+source /usr/share/makepkg/util/schema.sh
-set -e
+set -eo pipefail
# set the pkgver variable in a PKGBUILD
@@ -41,3 +44,48 @@ pkgbuild_set_pkgrel() {
sed --regexp-extended "s|^(pkgrel=)${pkgrel}$|\1${new_pkgrel}|g" --in-place PKGBUILD
}
+pkgbuild_update_checksums() {
+ local status_file=$1
+ local builddir newbuildfile sumtypes newsums
+
+ [[ -z ${WORKDIR:-} ]] && setup_workdir
+
+ builddir=$(mktemp --tmpdir="${WORKDIR}" --directory update-checksums.XXXXXX)
+ newbuildfile="${builddir}/PKGBUILD"
+
+ # generate new integrity checksums
+ if ! newsums=$(BUILDDIR=${builddir} makepkg_generate_integrity 2>"${status_file}"); then
+ printf 'Failed to generate new checksums'
+ return 1
+ fi
+
+ # early exit if no integrity checksums are needed
+ if [[ -z ${newsums} ]]; then
+ return 0
+ fi
+
+ # replace the integrity sums and write it to a temporary file
+ sumtypes=$(IFS='|'; echo "${known_hash_algos[*]}")
+ if ! awk --assign=sumtypes="${sumtypes}" --assign=newsums="${newsums}" '
+ $0 ~"^[[:blank:]]*(" sumtypes ")sums(_[^=]+)?\\+?=", $0 ~ "\\)[[:blank:]]*(#.*)?$" {
+ if (!w) {
+ print newsums
+ w++
+ }
+ next
+ }
+
+ 1
+ END { if (!w) print newsums }' PKGBUILD > "${newbuildfile}"; then
+ printf 'Failed to replace the generated checksums'
+ return 1
+ fi
+
+ # overwrite the original PKGBUILD while preserving permissions
+ if ! cat -- "${newbuildfile}" > PKGBUILD; then
+ printf "Failed to write to the PKGBUILD file"
+ return 1
+ fi
+
+ return 0
+}