7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/pledgestrike/downloader.rb', line 7
def self.ensure_binary!
bin_name = Gem.win_platform? ? "pledgestrike.exe" : "pledgestrike"
bin_dir = File.join(Gem.dir, "bin")
bin_path = File.join(bin_dir, bin_name)
return bin_path if File.file?(bin_path)
target = case RUBY_PLATFORM
when /linux.*x86_64/ then "x86_64-unknown-linux-musl"
when /darwin.*x86_64/ then "x86_64-apple-darwin"
when /darwin.*arm64/ then "aarch64-apple-darwin"
end
unless target
warn "PledgeStrike: unsupported platform #{RUBY_PLATFORM}"
exit 1
end
ext = Gem.win_platform? ? "zip" : "tar.gz"
filename = "pledgestrike-#{VERSION}-#{target}.#{ext}"
url = "https://github.com/pledgeandgrow/pledgestrike/releases/download/v#{VERSION}/#{filename}"
FileUtils.mkdir_p(bin_dir)
tmp = File.join(bin_dir, filename)
warn "PledgeStrike: downloading #{filename}..."
URI.open(url) { |f| File.binwrite(tmp, f.read) }
if Gem.win_platform?
system("cd #{bin_dir} && unzip -o #{filename}")
else
system("cd #{bin_dir} && tar xzf #{filename}")
FileUtils.chmod(0o755, bin_path)
end
File.delete(tmp)
bin_path
end
|