32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'ext/extconf.rb', line 32
def download_binary
url = "https://github.com/#{GITHUB_REPO}/releases/download/#{VERSION}/bivvy-#{platform}.tar.gz"
puts "Downloading bivvy from #{url}"
uri = URI(url)
response = Net::HTTP.get_response(uri)
while response.is_a?(Net::HTTPRedirection)
uri = URI(response["location"])
response = Net::HTTP.get_response(uri)
end
raise "Download failed: #{response.code}" unless response.is_a?(Net::HTTPSuccess)
bin_dir = File.expand_path("../../exe", __dir__)
FileUtils.mkdir_p(bin_dir)
Gem::Package::TarReader.new(Zlib::GzipReader.new(StringIO.new(response.body))) do |tar|
tar.each do |entry|
if entry.file? && entry.full_name == "bivvy"
File.open(File.join(bin_dir, "bivvy-bin"), "wb") do |f|
f.write(entry.read)
end
FileUtils.chmod(0o755, File.join(bin_dir, "bivvy-bin"))
end
end
end
puts "bivvy installed successfully"
end
|