Skip to content

Instantly share code, notes, and snippets.

@andrewgross
Created April 15, 2013 19:23
Show Gist options
  • Save andrewgross/5390616 to your computer and use it in GitHub Desktop.
Save andrewgross/5390616 to your computer and use it in GitHub Desktop.
Remote File Pattern with Checksum Validation
url = node['redisio']['mirror']
base_name = node['redisio']['base_name']
version = node['redisio']['version']
extension = node['redisio']['artifact_type']
tarball_name = "#{base_name}#{version}"
tarball = "#{tarball_name}.#{extension}"
download_url = "#{url}/#{tarball}"
download_dir = node['redisio']['download_dir']
sha256_checksum = node['redisio']['sha256_checksum']
# Install from source
remote_file "Download Redis Source" do
path "#{download_dir}/#{tarball}"
source download_url
backup false
checksum sha256_checksum
notifies :create, "ruby_block[Validate Tarball Checksum]", :immediately
not_if { redis_exists? && node['redisio']['safe_install'] }
end
ruby_block "Validate Tarball Checksum" do
action :nothing
block do
require 'digest'
checksum = Digest::SHA1.file("#{download_dir}/#{tarball}").hexdigest
Chef::Log.debug("Computed Tarball Checksum: #{checksum}")
Chef::Log.debug("Expected Tarball Checksum: #{node['redisio']['sha1_checksum']}")
if checksum != node['redisio']['sha1_checksum']
raise "Downloaded Tarball Checksum #{checksum} does not match known checksum #{node['redisio']['sha1_checksum']}"
end
end
notifies :run, "execute[Unpack Redis Tarball]", :immediately
end
execute "Unpack Redis Tarball" do
command "tar -xvzf #{tarball}"
action :nothing
cwd download_dir
notifies :run, "execute[Make Redis]", :immediately
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment