class BearerCli::UpdateCliService
Constants
- BINARY_NAME
- BIN_NAME
- URL_BASE
Public Class Methods
download_url(os, arch)
click to toggle source
# File lib/bearer_cli/update_cli_service.rb, line 26 def self.download_url(os, arch) arch = execute("uname -m | awk '{print tolower($0)}'") if os == "linux" case arch when "i386" "#{URL_BASE}/#{os}/production/386/bin/#{BINARY_NAME}" when "x86_64" "#{URL_BASE}/#{os}/production/amd64/bin/#{BINARY_NAME}" when "aarch64" "#{URL_BASE}/#{os}/production/arm64/bin/#{BINARY_NAME}" end end
execute(cmd)
click to toggle source
# File lib/bearer_cli/update_cli_service.rb, line 39 def self.execute(cmd) Open3.capture3(cmd).first&.strip end
run(bindir)
click to toggle source
# File lib/bearer_cli/update_cli_service.rb, line 9 def self.run(bindir) os = execute("uname -s | awk '{print tolower($0)}'") arch = execute("uname -p | awk '{print tolower($0)}'") uri = URI.parse(download_url(os, arch)) executable = File.join(bindir, BIN_NAME) Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| resp = http.get(uri.path) File.open(executable, "wb") do |file| file.write(resp.body) end end execute("chmod u+x #{executable}") end