forked from specht/proteomatic-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
md5sum.rb
executable file
·53 lines (49 loc) · 1.74 KB
/
md5sum.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/env ruby
# Copyright (c) 2009 Michael Specht
#
# This file is part of Proteomatic.
#
# Proteomatic is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Proteomatic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Proteomatic. If not, see <http://www.gnu.org/licenses/>.
require './include/ruby/proteomatic'
require 'digest/md5'
require 'yaml'
class Md5Sum < ProteomaticScript
def run()
lk_Digest = Digest::MD5.new()
files = @input[:files].sort do |a, b|
File::basename(a) <=> File::basename(b)
end
print "Digesting #{files.size} file#{files.size > 1 ? 's' : ''}..."
files.each do |path|
File.open(path, 'rb') do |lk_File|
while !lk_File.eof?
ls_Chunk = lk_File.read(8 * 1024 * 1024) # read 8M
lk_Digest << ls_Chunk
end
end
end
puts
md5 = lk_Digest.hexdigest
puts "The determined MD5 is #{md5}"
unless @param[:assertMd5].empty?
if @param[:assertMd5] != md5
puts "Error: The determined MD5 does not match the asserted MD5."
exit 1
else
puts "Success: The determined MD5 matches the asserted MD5."
end
end
end
end
script = Md5Sum.new