[2/4] updpkgsums: rely on makepkg's exported schema declaration for algo types

Message ID 20191023061359.820902-2-eschwartz@archlinux.org
State Accepted
Headers show
Series
  • [1/4] Port to libmakepkg
Related show

Commit Message

Eli Schwartz Oct. 23, 2019, 6:13 a.m. UTC
Rather than heuristically match (md|sha)[[:digit:]]+sums or even .*sums,
read makepkg's internal description of known hash algorithms, and use it
to generate a search pattern. This ensures that we will always be in
sync with the makepkg installed on the user's system.

Fixes support for the newly added b2sums algorithm.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---
 src/updpkgsums.sh.in | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Patch

diff --git a/src/updpkgsums.sh.in b/src/updpkgsums.sh.in
index 9c545ea..41965f5 100644
--- a/src/updpkgsums.sh.in
+++ b/src/updpkgsums.sh.in
@@ -22,6 +22,11 @@  shopt -s extglob
 declare -r myname='updpkgsums'
 declare -r myver='@PACKAGE_VERSION@'
 
+LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
+
+# Import libmakepkg
+source "$LIBRARY"/util/schema.sh
+
 usage() {
 	printf "%s v%s\n" "${myname}" "${myver}"
 	echo
@@ -92,9 +97,10 @@  export BUILDDIR=$(mktemp -d  "${TMPDIR:-/tmp}/updpkgsums.XXXXXX")
 newbuildfile=$(mktemp "${TMPDIR:-/tmp}/updpkgsums.XXXXXX")
 
 trap "rm -rf '$BUILDDIR' '$newbuildfile'" EXIT
+sumtypes=$(IFS='|'; echo "${known_hash_algos[*]}")
 newsums=$(makepkg -g -p "$buildfile" "${MAKEPKG_OPTS[@]}") || die 'Failed to generate new checksums'
-awk -v newsums="$newsums" '
-	/^[[:blank:]]*(md|sha)[[:digit:]]+sums(_[^=]+)?=/,/\)[[:blank:]]*(#.*)?$/ {
+awk -v sumtypes="$sumtypes" -v newsums="$newsums" '
+	$0 ~"^[[:blank:]]*(" sumtypes ")sums(_[^=]+)?=", $0 ~ "\\)[[:blank:]]*(#.*)?$" {
 		if (!w) {
 			print newsums
 			w++