| 1 |
#!/usr/bin/env ruby |
| 2 |
|
| 3 |
require 'open-uri' |
| 4 |
require 'digest/sha2' |
| 5 |
require 'tempfile' |
| 6 |
|
| 7 |
raise "Usage: #{$0} NEW_VERSION" unless ARGV.size == 1 |
| 8 |
new_version = ARGV[0] |
| 9 |
|
| 10 |
major_minor = new_version.split('.')[0..1].join('.') |
| 11 |
|
| 12 |
url = "https://github.com/openssl/openssl/releases/download/openssl-#{new_version}/openssl-#{new_version}.tar.gz" |
| 13 |
sha = nil |
| 14 |
|
| 15 |
Tempfile.create(['openssl', '.tar.gz']) do |tmpfile| |
| 16 |
URI.open(url) do |remote_file| |
| 17 |
IO.copy_stream(remote_file, tmpfile) |
| 18 |
end |
| 19 |
tmpfile.rewind |
| 20 |
|
| 21 |
sha = Digest::SHA256.file(tmpfile.path).hexdigest |
| 22 |
end |
| 23 |
|
| 24 |
Dir.glob('share/ruby-build/*') do |file| |
| 25 |
contents = File.read(file) |
| 26 |
|
| 27 |
openssl_package = "\"openssl-#{major_minor}" |
| 28 |
|
| 29 |
next unless contents.include? openssl_package |
| 30 |
|
| 31 |
lines = contents.lines |
| 32 |
line = lines.find { |line| line.include? openssl_package } |
| 33 |
old_version = line[/"openssl-([\d.]+[a-z]?)"/, 1] or raise |
| 34 |
line.gsub!(old_version, new_version) |
| 35 |
line.sub!(/\.tar\.gz#(\h+)"/, ".tar.gz##{sha}\"") |
| 36 |
File.write(file, lines.join) |
| 37 |
end |