From 4fe0af90e651c8bf2e61fad8589d58406f94c9cf Mon Sep 17 00:00:00 2001 From: IsmailM Date: Thu, 10 Jun 2021 23:06:44 +0100 Subject: [PATCH] Use mac's md5 if md5sum is not available Fixes #4 - Also fixes a loop (where it kept on downloading and then deleting, and then downloading... ) if md5sum was not available --- README.md | 11 ++--------- lib/ncbi-blast-dbs.rake | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4acf10a..09a96bc 100644 --- a/README.md +++ b/README.md @@ -8,20 +8,13 @@ or re-downloaded if corrupt. Aborted downloads are safely resumed. `ncbi-blast-dbs` is faster than NCBI's `update_blastdb.pl`. But unlike `update_blastdb.pl`, which is a pure Perl script, `ncbi-blast-dbs` delegates -download and checksum verification to `wget` and `md5sum` and is thus not as -universal. +download and checksum verification to `wget` and `md5sum` / `md5` and is thus +not as universal. ### Installation gem install ncbi-blast-dbs -#### Note for macOS users - -If `md5sum` command is not present, you can install it using -[`Homebrew`](https://brew.sh): - - brew install md5sha1sum - ### Usage #### List available BLAST databases diff --git a/lib/ncbi-blast-dbs.rake b/lib/ncbi-blast-dbs.rake index ea58e90..e02af70 100644 --- a/lib/ncbi-blast-dbs.rake +++ b/lib/ncbi-blast-dbs.rake @@ -12,14 +12,26 @@ def download(url) # the server is newer and if so download the new copy. sh "wget -N --no-verbose #{url}" - # Immediately download md5 and verify the tarball. Re-download tarball if - # corrupt; extract otherwise. - sh "wget --no-verbose #{url}.md5 && md5sum -c #{file}.md5" do |matched, _| - if !matched - sh "rm #{file} #{file}.md5"; download(url) - else - sh "tar xf #{file}" - end + # Download Md5 + sh "wget --no-verbose #{url}.md5" + + # Verify the tarball using md5sum or md5 + if system("which md5sum > /dev/null") + matched = system("md5sum -c #{file}.md5") + elsif system("which md5 > /dev/null") + md5_out = %x[md5 -q #{file}].chomp + md5_actual = File.read("#{file}.md5").split[0] + matched = md5_out == md5_actual + else + puts "Cannot find md5sum or md5. Please install md5sum or md5 and try again" + exit 1 + end + + # Re-download tarball if corrupt; extract otherwise. + if !matched + sh "rm #{file} #{file}.md5"; download(url) + else + sh "tar xf #{file}" end end