install-eclipse.rb
def download_eclipse(eclipse_version)
  # Get the SHA-1 hash to verify
  puts "*** Getting SHA-1 hash"

  params = { :file => eclipse_version, :type => "sha1" }
  uri = URI(SHA_BASE_URL)
  uri.query = URI.encode_www_form(params)
  response = Net::HTTP.get_response(uri)
  check_err(response, "Cannot download SHA-1 hash")
  expected_hash = response.body.split.first
  puts "*** SHA-1 hash is #{expected_hash}"

  # Get a list of mirrors
  puts "*** Getting list of mirrors"
  uri = URI(DOWNLOAD_BASE_URL)
  params = { :file => eclipse_version, :protocol => 'http', :format => 'xml' }
  uri.query = URI.encode_www_form(params)
  response = Net::HTTP.get_response(uri)
  check_err(response, "Cannot download Eclpse mirror list")

  # Choose a random mirror
  mirrors = []
  doc = REXML::Document.new(response.body)
  doc.elements.each("mirrors/mirror") { |e| mirrors << e.attribute("url").to_s }
  puts "** #{mirrors.size} mirrors"
  url = mirrors[ Kernel.rand(mirrors.size) ]
  
  # Download the eclipse binary
  puts "*** Downloading from mirror"
  puts "** #{url}"
  tar_file = File.basename eclipse_version
  run_and_check_err("curl #{url} > #{tar_file}")

  # Check the SHA-1 hash
  actual_hash = run_and_check_err("shasum #{tar_file}").split.first
  if expected_hash != actual_hash then
    $stderr.puts "*** ERROR SHA-1 CHECKSUMS DO NOT MATCH, POSSIBLE MALICIOUS ACTIVITY"
    $stderr.puts "#{expected_hash} Expected"
    $stderr.puts "#{actual_hash} Hash of downloaded file #{tar_file}"
    exit 1
  end
  puts "*** SHA-1 hash passes"

  # Untar downloaded file
  puts "*** Untaring file to create installation"
  run_and_check_err("tar jxf #{tar_file}")

  puts "*** Removing tar file"
  run_and_check_err("rm #{tar_file}")
end
# Download the supplied Eclipse version from a mirror supplied on
# eclipse.org while checking that it has the expected hash.
Download the supplied Eclipse version from a mirror supplied on
eclipse.org while checking that it has the expected hash.
Download the supplied Eclipse version from a mirror supplied on eclipse . org while checking that it has the expected hash .
def download_eclipse(eclipse_version)
  puts "*** Getting SHA-1 hash"
  params = { :file => eclipse_version, :type => "sha1" }
  uri = URI(SHA_BASE_URL)
  uri.query = URI.encode_www_form(params)
  response = Net::HTTP.get_response(uri)
  check_err(response, "Cannot download SHA-1 hash")
  expected_hash = response.body.split.first
  puts "*** SHA-1 hash is #{expected_hash}"
  puts "*** Getting list of mirrors"
  uri = URI(DOWNLOAD_BASE_URL)
  params = { :file => eclipse_version, :protocol => 'http', :format => 'xml' }
  uri.query = URI.encode_www_form(params)
  response = Net::HTTP.get_response(uri)
  check_err(response, "Cannot download Eclpse mirror list")
  mirrors = []
  doc = REXML::Document.new(response.body)
  doc.elements.each("mirrors/mirror") { |e| mirrors << e.attribute("url").to_s }
  puts "** #{mirrors.size} mirrors"
  url = mirrors[ Kernel.rand(mirrors.size) ]
  puts "*** Downloading from mirror"
  puts "** #{url}"
  tar_file = File.basename eclipse_version
  run_and_check_err("curl #{url} > #{tar_file}")
  actual_hash = run_and_check_err("shasum #{tar_file}").split.first
  if expected_hash != actual_hash then
    $stderr.puts "*** ERROR SHA-1 CHECKSUMS DO NOT MATCH, POSSIBLE MALICIOUS ACTIVITY"
    $stderr.puts "#{expected_hash} Expected"
    $stderr.puts "#{actual_hash} Hash of downloaded file #{tar_file}"
    exit 1
  end
  puts "*** SHA-1 hash passes"
  puts "*** Untaring file to create installation"
  run_and_check_err("tar jxf #{tar_file}")
  puts "*** Removing tar file"
  run_and_check_err("rm #{tar_file}")
end
def download_eclipse ( eclipse_version ) puts "*** Getting SHA-1 hash" params = { :file => eclipse_version , :type => "sha1" } uri = URI ( SHA_BASE_URL ) uri . query = URI . encode_www_form ( params ) response = Net :: HTTP . get_response ( uri ) check_err ( response , "Cannot download SHA-1 hash" ) expected_hash = response . body . split . first puts "*** SHA-1 hash is #{expected_hash}" puts "*** Getting list of mirrors" uri = URI ( DOWNLOAD_BASE_URL ) params = { :file => eclipse_version , :protocol => 'http' , :format => 'xml' } uri . query = URI . encode_www_form ( params ) response = Net :: HTTP . get_response ( uri ) check_err ( response , "Cannot download Eclpse mirror list" ) mirrors = [ ] doc = REXML :: Document . new ( response . body ) doc . elements . each ( "mirrors/mirror" ) { | e | mirrors << e . attribute ( "url" ) . to_s } puts "** #{mirrors.size} mirrors" url = mirrors [ Kernel . rand ( mirrors . size ) ] puts "*** Downloading from mirror" puts "** #{url}" tar_file = File . basename eclipse_version run_and_check_err ( "curl #{url} > #{tar_file}" ) actual_hash = run_and_check_err ( "shasum #{tar_file}" ) . split . first if expected_hash != actual_hash then $stderr . puts "*** ERROR SHA-1 CHECKSUMS DO NOT MATCH, POSSIBLE MALICIOUS ACTIVITY" $stderr . puts "#{expected_hash} Expected" $stderr . puts "#{actual_hash} Hash of downloaded file #{tar_file}" exit 1 end puts "*** SHA-1 hash passes" puts "*** Untaring file to create installation" run_and_check_err ( "tar jxf #{tar_file}" ) puts "*** Removing tar file" run_and_check_err ( "rm #{tar_file}" ) end
Download the supplied Eclipse version from a mirror supplied on
eclipse.org while checking that it has the expected hash.
Download the supplied Eclipse version from a mirror supplied on eclipse . org while checking that it has the expected hash .
# Get the SHA-1 hash to verify # Get a list of mirrors # Choose a random mirror # Download the eclipse binary # Check the SHA-1 hash # Untar downloaded file
eclipse_version