0

I would like to use the md5sums function of without keeping track of new 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 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 from the website using a shell script that may call tools usually preinstalled on an installation into a variable that will strictly contain only the ?

  • Have you seen the sections of the PKGBUILD documentation about signatures and integrity? That project includes .asc signatures, so you can use those for validation and skip the checksum step altogether. – JigglyNaga Jun 21 '16 at 10:44
  • You can just set the value of the checksum for a file to SKIP and makepkg will not try to verify the checksum of that file. – Wieland Jun 21 '16 at 10:54
  • @JigglyNaga indeed, but that would still be useful to learn how it could be done. – Zulgrib Jun 22 '16 at 7:58
  • @Wieland Cannot guarantee the download won't screw up – Zulgrib Jun 22 '16 at 7:59
1

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
    
| improve this answer | |
  • It works but it doesn't seem to look specifically for a span of class md5sum, is it because it is not possible or is it because it was simpler this way ? What about resilience to small changes then ? – Zulgrib Jun 22 '16 at 8:03
  • @Zulgrib Purely for simplicity/laziness. I'll add some notes about what each step does. – JigglyNaga Jun 22 '16 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.