lib/ncbi-blast-dbs.rake in ncbi-blast-dbs-0.0.6 vs lib/ncbi-blast-dbs.rake in ncbi-blast-dbs-0.0.7
- old
+ new
@@ -4,23 +4,35 @@
# local copy is older than at the given URL, or if the local copy is corrupt.
def download(url)
file = File.basename(url)
# Resume an interrupted download or fetch the file for the first time. If
# the file on the server is newer, then it is downloaded from start.
- sh "wget -Nc #{url}"
+ sh "wget -Nc --no-verbose #{url}"
# If the local copy is already fully retrieved, then the previous command
# ignores the timestamp. So we check with the server again if the file on
# the server is newer and if so download the new copy.
- sh "wget -N #{url}"
+ sh "wget -N --no-verbose #{url}"
- # Immediately download md5 and verify the tarball. Re-download tarball if
- # corrupt; extract otherwise.
- sh "wget #{url}.md5 && md5sum -c #{file}.md5" do |matched, _|
- if !matched
- sh "rm #{file} #{file}.md5"; download(url)
- else
- sh "tar xvf #{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
# Connects to NCBI's FTP server, gets the URL of all database volumes and
# returns them grouped by database name: