Skip to content

Commit

Permalink
Merge pull request #11 from IsmailM/master
Browse files Browse the repository at this point in the history
Use mac's md5 if md5sum is not available
  • Loading branch information
yeban authored Jun 16, 2021
2 parents 0f68138 + 4fe0af9 commit 0d3a1df
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
11 changes: 2 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 20 additions & 8 deletions lib/ncbi-blast-dbs.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0d3a1df

Please sign in to comment.