Last active
August 29, 2015 14:27
-
-
Save dhoer/ce54fbf53780979038bc to your computer and use it in GitHub Desktop.
Download Oracle JDK via Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires open_uri_redirections gem:
https://github.com/open-uri-redirections/open_uri_redirections