Class: GitCredentialManager::Installer
- Inherits:
-
Object
- Object
- GitCredentialManager::Installer
- Defined in:
- lib/git_credential_manager/installer.rb
Instance Method Summary collapse
- #already_installed? ⇒ Boolean
- #base_url ⇒ Object
- #ci? ⇒ Boolean
- #ci_env_keys ⇒ Object
- #complete_install ⇒ Object
- #debug? ⇒ Boolean
- #debug_message(msg) ⇒ Object
- #download(url_string) ⇒ Object
- #download_and_save(url, output) ⇒ Object
- #download_files(files) ⇒ Object
- #goarch ⇒ Object
- #goos ⇒ Object
-
#initialize(host_os = nil, host_cpu = nil) ⇒ Installer
constructor
A new instance of Installer.
- #install ⇒ Object
- #install_async ⇒ Object
- #installer_files ⇒ Object
- #path_for(*file) ⇒ Object
- #product ⇒ Object
- #skip_install? ⇒ Boolean
- #start_script(full_path) ⇒ Object
- #url_for(file) ⇒ Object
- #version_file ⇒ Object
Constructor Details
#initialize(host_os = nil, host_cpu = nil) ⇒ Installer
Returns a new instance of Installer.
7 8 9 10 |
# File 'lib/git_credential_manager/installer.rb', line 7 def initialize(host_os = nil, host_cpu = nil) @host_os = host_os @host_cpu = host_cpu end |
Instance Method Details
#already_installed? ⇒ Boolean
24 25 26 |
# File 'lib/git_credential_manager/installer.rb', line 24 def already_installed? File.exist?(version_file) end |
#base_url ⇒ Object
161 162 163 |
# File 'lib/git_credential_manager/installer.rb', line 161 def base_url "https://git.disroot.org/git-ecosystem/#{product}/raw/branch/main" end |
#ci? ⇒ Boolean
174 175 176 177 178 179 180 |
# File 'lib/git_credential_manager/installer.rb', line 174 def ci? if ENV["CI"] == "true" || ENV["CI"] == "1" return true end ci_env_keys.any? { |k| ENV.key?(k) } end |
#ci_env_keys ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/git_credential_manager/installer.rb', line 182 def ci_env_keys [ "APPVEYOR", "bamboo_agentId", "BITBUCKET_BUILD_NUMBER", "BITRISE_IO", "BUDDY_WORKSPACE_ID", "BUILD_BUILDURI", "BUILDKITE", "CF_BUILD_ID", "CF_PAGES", "CIRCLECI", "CIRRUS_CI", "CODEBUILD_BUILD_ID", "DISTELLI_APPNAME", "DRONE", "GITHUB_ACTIONS", "GITLAB_CI", "JB_SPACE_EXECUTION_NUMBER", "JENKINS_URL", "NETLY", "NOW_GITHUB_DEPLOYMENT", "SAILCI", "SCREWDRIVER", "SEMAPHORE", "SHIPPABLE", "TEAMCITY_VERSION", "TRAVIS", "VELA", "VERCEL", "WERCKER_MAIN_PIPELINE_STARTED", ] end |
#complete_install ⇒ Object
32 33 34 |
# File 'lib/git_credential_manager/installer.rb', line 32 def complete_install File.write(version_file, "1") end |
#debug? ⇒ Boolean
153 154 155 |
# File 'lib/git_credential_manager/installer.rb', line 153 def debug? ENV["DEBUG"] == "true" end |
#debug_message(msg) ⇒ Object
148 149 150 151 |
# File 'lib/git_credential_manager/installer.rb', line 148 def (msg) return unless debug? puts msg end |
#download(url_string) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/git_credential_manager/installer.rb', line 121 def download(url_string) url = URI.parse(url_string) http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE # Disable SSL verification request = Net::HTTP::Get.new(url.request_uri) request["User-Agent"] = "Git" response = http.request(request) case response when Net::HTTPSuccess response.body when Net::HTTPRedirection "Redirected to: #{response["location"]}" nil else "HTTP Error: #{response.code} #{response.}" nil end rescue => e "Error: #{e.}" nil end |
#download_and_save(url, output) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/git_credential_manager/installer.rb', line 62 def download_and_save(url, output) "Downloading '#{url}' to '#{output}' ..." content = download(url) if content.nil? throw "Can't download '#{url}'" end File.write(output, content) end |
#download_files(files) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/git_credential_manager/installer.rb', line 73 def download_files(files) if files.empty? "No files to download ... #{goos} #{goarch}" return end downloaded = {} files.each do |key, file| url = url_for("#{goos}/#{file}") output = path_for("package", file) download_and_save(url, output) downloaded[key] = output end downloaded end |
#goarch ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/git_credential_manager/installer.rb', line 99 def goarch if @host_cpu == "x86_64" || @host_cpu == "i686" return "amd64" elsif @host_cpu == "aarch64" || @host_cpu == "arm64" return "arm64" else return nil end end |
#goos ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/git_credential_manager/installer.rb', line 90 def goos case @host_os when /darwin/i then "darwin" when /linux/i then "linux" when /mingw|mswin|win/i then "windows" else nil end end |
#install ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/git_credential_manager/installer.rb', line 43 def install return if skip_install? files = installer_files downloaded = download_files(files) deployment_script = downloaded[:deploy] start_script(deployment_script) complete_install rescue StandardError => e (e) end |
#install_async ⇒ Object
36 37 38 39 40 41 |
# File 'lib/git_credential_manager/installer.rb', line 36 def install_async return if skip_install? exe = path_for("bin", "install") ruby = RbConfig.ruby Process.spawn("#{ruby} \"#{exe}\"") end |
#installer_files ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/git_credential_manager/installer.rb', line 109 def installer_files if goos == "darwin" { deploy: "deploy.sh", package: "notification-service-#{goarch}" } elsif goos == "linux" && goarch == "amd64" { deploy: "deploy.sh", package: "git-credential-manager" } elsif goos == "windows" && goarch == "amd64" { deploy: "deploy.ps1", package: "git-credential-manager-amd64.zip" } else Hash.new end end |
#path_for(*file) ⇒ Object
169 170 171 172 |
# File 'lib/git_credential_manager/installer.rb', line 169 def path_for(*file) p = File.join(__dir__, "..", "..", *file) File.(p) end |
#product ⇒ Object
157 158 159 |
# File 'lib/git_credential_manager/installer.rb', line 157 def product "git-credential-manager" end |
#skip_install? ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/git_credential_manager/installer.rb', line 12 def skip_install? if already_installed? "Skip: Already installed" return true end if ci? "Skip: CI" return true end end |
#start_script(full_path) ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/git_credential_manager/installer.rb', line 54 def start_script(full_path) if goos == "windows" Process.spawn("powershell -ExecutionPolicy bypass \"#{full_path}\"") else Process.spawn("/bin/sh \"#{full_path}\" 2>&1 >/dev/null") end end |
#url_for(file) ⇒ Object
165 166 167 |
# File 'lib/git_credential_manager/installer.rb', line 165 def url_for(file) "#{base_url}/#{file}" end |
#version_file ⇒ Object
28 29 30 |
# File 'lib/git_credential_manager/installer.rb', line 28 def version_file path_for("package", VERSION) end |