You are not logged in.

#1 2018-04-10 12:15:23

Magissia
Member
Registered: 2013-05-06
Posts: 7

Dynamic $hash values ?

Greetings, I would like to reduce to bare minimum the time required to update my PHP PKGBUILD, using these few lines, i'm able to retrieve the hash of the last php5 version.

str="curl http://php.net/downloads.php | grep -A 1 -G php-$pkgver.tar.xz | grep -A 1 -G sha"
	str=$(eval $str)
	hash=${str%</s*}
	hash=${hash#*>}

But running this in prepare doesn't allow to alter upper's hash variable, running it elsewhere seems to wreck havoc.
Where should I run this to properly affect sha256sums array to use $hash variable for the first element of the array ?

I know that the PKGBUILD would break as soon as PHP release a new version, but that's okay and will make a good reminder to check for new version.

Last edited by Magissia (2018-04-10 12:16:28)

Offline

#2 2018-04-10 16:10:29

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Dynamic $hash values ?

Run it outside prepare then. It's not meant to "prepare" the build directory, so why do you think you should run it there?

What "havoc" is it wreaking, exactly?

...

BTW this whole thing could be replaced by a single `sed` command modifying the curl output.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3 2018-04-10 16:36:50

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dynamic $hash values ?

I actually wrote the sed command before noting that Eschwartz commented on it.  Regardless of the tool used (awk, grep, sed) piping through multiple is just silly (and more so when that is followed by yet more shell string munging).  Particularly the -A 1 on the second grep is odd: there is no other context left, and you wouldn't want it if there was.  And assuming you want the most recent, you don't even need the version number inserted in there:

hash=$(curl ... | sed -n '/php-.*.tar.xz/{n;s/[^>]*>\([^<]*\).*/\1/p;q;}')

Or if you really do just want the most recent / top one on the page, then one grep would suffice:

hash=$(curl -s http://php.net/downloads.php | grep -om1 '[0-9a-f]\{64\}')

Last edited by Trilby (2018-04-10 16:44:01)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2018-07-06 10:07:47

Magissia
Member
Registered: 2013-05-06
Posts: 7

Re: Dynamic $hash values ?

Hello, I want the most recent in the v5 branch specifically.
Thank you for your answers

Offline

#5 2018-07-06 12:12:44

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,517
Website

Re: Dynamic $hash values ?

Then modify the sed script.  This would do:

/id="v5"/ {
        :loop
        n
        /tar.xz/ {
                n
                s/[^>]*>\([^<]*\).*/\1/
                p
                q
        }
        bloop
}

But in this case, I think awk would now be better:

curl -s $url | awk -F '[<>]' '/id="v5"/ { on=1; } /tar.xz/ && on==1 { getline; print $3; quit; }'

"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB