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

Message ID 20190417024942.19420-1-eschwartz@archlinux.org
State Deferred
Headers show
Series [1/2] updpkgsums: rely on makepkg's exported schema declaration for algo types | expand

Commit Message

Eli Schwartz April 17, 2019, 2:49 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>
---

This depends on pacman from git master, because schema.sh does not exist
in pacman 5.1.x

 src/updpkgsums.sh.in | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Johannes Löthberg April 23, 2019, 6:47 p.m. UTC | #1
Sorry for the delay, I've been rather busy as of late..

Excerpts from Eli Schwartz's message of April 17, 2019 4:49:
> 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>
> ---

I really like the idea, but...

> 
> This depends on pacman from git master, because schema.sh does not exist
> in pacman 5.1.x
> 
>  src/updpkgsums.sh.in | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/src/updpkgsums.sh.in b/src/updpkgsums.sh.in
> index 9c545ea..618f471 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:-'@datarootdir@/makepkg'}

... I don't really like using @datarootdir@ for this, since we don't 
necessarily know that pacman was installed to the same datarootdir that 
we will be installed to.

Would be nicer if there was a libmakepkg.pc that pointed to the 
libmakepkg install dir, or at least its prefix, so we could query the 
system for the proper path..

> +
> +# 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++
> -- 
> 2.21.0
>
Eli Schwartz April 24, 2019, 5:35 p.m. UTC | #2
On 4/23/19 2:47 PM, Johannes Löthberg wrote:
> Sorry for the delay, I've been rather busy as of late..
> 
> Excerpts from Eli Schwartz's message of April 17, 2019 4:49:
>> 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>
>> ---
> 
> I really like the idea, but...
> 
>>
>> This depends on pacman from git master, because schema.sh does not exist
>> in pacman 5.1.x
>>
>>  src/updpkgsums.sh.in | 10 ++++++++--
>>  1 file changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/updpkgsums.sh.in b/src/updpkgsums.sh.in
>> index 9c545ea..618f471 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:-'@datarootdir@/makepkg'}
> 
> ... I don't really like using @datarootdir@ for this, since we don't 
> necessarily know that pacman was installed to the same datarootdir that 
> we will be installed to.
> 
> Would be nicer if there was a libmakepkg.pc that pointed to the 
> libmakepkg install dir, or at least its prefix, so we could query the 
> system for the proper path..

Pending
https://lists.archlinux.org/pipermail/pacman-dev/2019-April/023345.html

This patch is therefore delayed until then.

>> +
>> +# 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++
>> -- 
>> 2.21.0
>>

Patch

diff --git a/src/updpkgsums.sh.in b/src/updpkgsums.sh.in
index 9c545ea..618f471 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:-'@datarootdir@/makepkg'}
+
+# 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++