I would like to use the md5sums function of pkgbuild without keeping track of new hashsum at each update, and just change the pkgver variable to build a new version of my package.md5 are available on the official website of the project i'm interested in near the source archive download in a span of class value of md5sum As I know the hashsum will always be in a span of class md5sum right after the span of class releasedate , itself behind two a href having tar.xz in them, how can I extract the hashsum from the website using a shell script that may call tools usually preinstalled on an archlinux installation into a variable that will strictly contain only the hashsum ?
Using http remote MD5 hash
shell script;arch linux;hashsum;pkgbuild
If you are intent on scraping the hash off the page, then something like this will work.  It's the sort of one-liner I write for one-off use, because it's likely to break as soon as the layout changes:hashsum=$(curl http://php.net/downloads.php | grep -A1 -F >php-${pkgver}.tar.xz< | sed 1d | tr '>' '<' | cut -d '<' -f3 )To understand why this is an incredibly inflexible approach, it may help to look at the output of each stage.curl fetches the page and sends it to the standard output.  (If you don't have curl available, wget -O - will also work.)The output includes this:...<ul>          <li>      <a href=/get/php-7.0.7.tar.bz2/from/a/mirror>php-7.0.7.tar.bz2</a> <a href=/get/php-7.0.7.tar.bz2.asc/from/a/mirror>(sig)</a> [13,776Kb]          <span class=releasedate>26 May 2016</span>      <span class=md5sum>cc231de15146ca14a69610f695995ab8</span>      <span class=sha256>474f2925c4782b94016e3afbb17b14ff9cc6f4fdb6f6e231b36a378bb18a3d1a</span>              </li>          <li>      <a href=/get/php-7.0.7.tar.gz/from/a/mirror>php-7.0.7.tar.gz</a> <a href=/get/php-7.0.7.tar.gz.asc/from/a/mirror>(sig)</a> [17,792Kb]          <span class=releasedate>26 May 2016</span>      <span class=md5sum>197ec66d134da8968ddd0b89f1cfac2a</span>      <span class=sha256>66282ff4a9f88fe9607d9574e15bf335885b964245591a1740adb3f79c514a67</span>              </li>          <li>      <a href=/get/php-7.0.7.tar.xz/from/a/mirror>php-7.0.7.tar.xz</a> <a href=/get/php-7.0.7.tar.xz.asc/from/a/mirror>(sig)</a> [11,219Kb]          <span class=releasedate>26 May 2016</span>      <span class=md5sum>75f8d1693a470cefe2a50abd283eb291</span>      <span class=sha256>9cc64a7459242c79c10e79d74feaf5bae3541f604966ceb600c3d2e8f5fe4794</span>              </li>        <li>    <a href=http://windows.php.net/download#php-7.0>      Windows downloads    </a>  </li></ul>...grep -A1 returns the line containing that pattern (the name of the source file you need), plus 1 line following it:  <a href=/get/php-7.0.7.tar.xz/from/a/mirror>php-7.0.7.tar.xz</a> <a href=/get/php-7.0.7.tar.xz.asc/from/a/mirror>(sig)</a> [11,219Kb]          <span class=releasedate>26 May 2016</span>  <span class=md5sum>75f8d1693a470cefe2a50abd283eb291</span>We only care about the second line, so sed 1d deletes the first.  (If you want to be sure it's an md5sum, use grep 'class=md5sum' instead.)  <span class=md5sum>75f8d1693a470cefe2a50abd283eb291</span>The tr command turns all > to <.  This is not useful on its own, but turns the line into something that cut can work with:  <span class=md5sum<75f8d1693a470cefe2a50abd283eb291</span<Finally, cut treats those <s (including the ones that were previously >s) as delimiters, and extracts the 3rd item, ie. the hash:75f8d1693a470cefe2a50abd283eb291