Skip to content

Commit 4fe0af9

Browse files
committed
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
1 parent 0f68138 commit 4fe0af9

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

README.md

+2-9
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,13 @@ or re-downloaded if corrupt. Aborted downloads are safely resumed.
88

99
`ncbi-blast-dbs` is faster than NCBI's `update_blastdb.pl`. But unlike
1010
`update_blastdb.pl`, which is a pure Perl script, `ncbi-blast-dbs` delegates
11-
download and checksum verification to `wget` and `md5sum` and is thus not as
12-
universal.
11+
download and checksum verification to `wget` and `md5sum` / `md5` and is thus
12+
not as universal.
1313

1414
### Installation
1515

1616
gem install ncbi-blast-dbs
1717

18-
#### Note for macOS users
19-
20-
If `md5sum` command is not present, you can install it using
21-
[`Homebrew`](https://brew.sh):
22-
23-
brew install md5sha1sum
24-
2518
### Usage
2619

2720
#### List available BLAST databases

lib/ncbi-blast-dbs.rake

+20-8
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,26 @@ def download(url)
1212
# the server is newer and if so download the new copy.
1313
sh "wget -N --no-verbose #{url}"
1414

15-
# Immediately download md5 and verify the tarball. Re-download tarball if
16-
# corrupt; extract otherwise.
17-
sh "wget --no-verbose #{url}.md5 && md5sum -c #{file}.md5" do |matched, _|
18-
if !matched
19-
sh "rm #{file} #{file}.md5"; download(url)
20-
else
21-
sh "tar xf #{file}"
22-
end
15+
# Download Md5
16+
sh "wget --no-verbose #{url}.md5"
17+
18+
# Verify the tarball using md5sum or md5
19+
if system("which md5sum > /dev/null")
20+
matched = system("md5sum -c #{file}.md5")
21+
elsif system("which md5 > /dev/null")
22+
md5_out = %x[md5 -q #{file}].chomp
23+
md5_actual = File.read("#{file}.md5").split[0]
24+
matched = md5_out == md5_actual
25+
else
26+
puts "Cannot find md5sum or md5. Please install md5sum or md5 and try again"
27+
exit 1
28+
end
29+
30+
# Re-download tarball if corrupt; extract otherwise.
31+
if !matched
32+
sh "rm #{file} #{file}.md5"; download(url)
33+
else
34+
sh "tar xf #{file}"
2335
end
2436
end
2537

0 commit comments

Comments
 (0)