Skip to content

Instantly share code, notes, and snippets.

@dhoer
Last active August 29, 2015 14:27
Show Gist options
  • Save dhoer/ce54fbf53780979038bc to your computer and use it in GitHub Desktop.
Save dhoer/ce54fbf53780979038bc to your computer and use it in GitHub Desktop.
Download Oracle JDK via Ruby
require 'open-uri'
require 'open_uri_redirections'
require 'openssl'
def fetch(url, file, limit = 5)
fail ArgumentError, "too many download failures from #{url}" if limit == 0
load_open_uri_redirections
uri = URI(url)
begin
open(uri,
'Cookie' => 'oraclelicense=accept-securebackup-cookie',
allow_redirections: :all,
ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE) do |fin|
open(file, 'wb') do |fout|
while (buf = fin.read(8192))
fout.write buf
end
end
end
rescue
fetch(url, file, limit - 1)
end
end
fetch('https://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-windows-x64.exe', '/tmp/jdk-8u51-windows-x64.exe')
@dhoer
Copy link
Author

dhoer commented Aug 14, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment