lib/veewee/provider/core/helper/iso.rb in veewee-0.3.12 vs lib/veewee/provider/core/helper/iso.rb in veewee-0.4.0
- old
+ new
@@ -7,10 +7,11 @@
require 'open-uri'
require 'progressbar'
require 'highline/import'
require 'digest/md5'
require 'digest/sha1'
+ require 'digest/sha2'
def download_iso(url,filename)
if !File.exists?(env.config.veewee.iso_dir)
ui.info "Creating an iso directory"
FileUtils.mkdir(env.config.veewee.iso_dir)
@@ -69,10 +70,12 @@
case type
when :md5
checksum=Digest::MD5.new
when :sha1
checksum=Digest::SHA1.new
+ when :sha256
+ checksum=Digest::SHA256.new
else
raise Veewee::Error, "Unknown checksum type #{type}"
end
buflen=1024
@@ -88,11 +91,11 @@
end
def verify_sum(full_path,type)
filename = File.basename(full_path)
required_sum = self.instance_variable_get('@iso_'+type.to_s)
- ui.info "Verifying #{type} checksum : #{self.required_sum}"
+ ui.info "Verifying #{type} checksum : #{required_sum}"
file_sum = hashsum(full_path,type)
unless file_sum == required_sum
ui.error "The #{type} checksum for file #{filename } do not match: "
ui.error "- #{file_sum} (current) vs #{required_sum} (specified)"
@@ -106,22 +109,18 @@
if File.exists?(full_path)
ui.info ""
ui.info "The isofile #{filename} already exists."
else
-
- path1=Pathname.new(full_path)
- path2=Pathname.new(Dir.pwd)
- rel_path=path1.relative_path_from(path2).to_s
-
ui.info ""
ui.info "We did not find an isofile here : #{full_path}. \n\nThe definition provided the following download information:"
unless "#{self.iso_src}"==""
ui.info "- Download url: #{self.iso_src}"
end
ui.info "- Md5 Checksum: #{self.iso_md5}" if self.iso_md5
ui.info "- Sha1 Checksum: #{self.iso_sha1}" if self.iso_sha1
+ ui.info "- Sha256 Checksum: #{self.iso_sha256}" if self.iso_sha256
ui.info "#{self.iso_download_instructions}"
ui.info ""
if self.iso_src == ""
ui.info "Please follow the instructions above:"
@@ -146,13 +145,14 @@
ui.error "#{ex}"
raise Veewee::Error, "There was an error downloading #{self.iso_src}:\n#{ex}"
end
else
ui.info "You have selected manual download: "
- ui.info "curl -C - -L '#{self.iso_src}' -o '#{rel_path}'"
- ui.info "md5 '#{rel_path}' " if self.iso_md5
- ui.info "shasum '#{rel_path}' " if self.iso_sha1
+ ui.info "curl -C - -L '#{self.iso_src}' -o '#{full_path}'"
+ ui.info "md5 '#{full_path}' " if self.iso_md5
+ ui.info "shasum '#{full_path}' " if self.iso_sha1
+ ui.info "shasum -a 256 '#{rel_path}' " if self.iso_sha256
ui.info ""
exit
end
unless File.readable?(full_path)
@@ -163,9 +163,10 @@
end
verify_sum(full_path,:md5) if options["checksum"] && !self.iso_md5.nil?
verify_sum(full_path,:sha1) if options["checksum"] && !self.iso_sha1.nil?
+ verify_sum(full_path,:sha256) if options["checksum"] && !self.iso_sha256.nil?
end
end #Module
end #Module