-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
/
Copy pathgpg.rb
50 lines (37 loc) · 1.2 KB
/
gpg.rb
1
2
3
4
5
6
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class Cask::GpgCheck
attr_reader :available
def initialize(cask, command=Cask::SystemCommand)
@command = command
@cask = cask
@available = @cask.gpg ? installed? : false
end
def installed?
cmd = @command.run('/usr/bin/type',
:args => ['-p', 'gpg'])
# if `gpg` is found, return its absolute path
cmd.success? ? cmd.stdout : false
end
def fetch_sig(force=false)
unversioned_cask = @cask.version.is_a?(Symbol)
cached = @cask.metadata_subdir('gpg') unless unversioned_cask
meta_dir = cached || @cask.metadata_subdir('gpg', :now, true)
sig_path = meta_dir.join("signature.asc")
curl(@cask.gpg.signature, '-o', sig_path.to_s) unless cached || force
sig_path
end
def import_key
args = case
when @cask.gpg.key_id then ['--recv-keys', @cask.gpg.key_id]
when @cask.gpg.key_url then ['--fetch-key', @cask.gpg.key_url.to_s]
end
@command.run!('gpg', :args => args)
end
def verify(file)
import_key
sig = fetch_sig
ohai "Verifying GPG signature for #{@cask}"
@command.run!('gpg',
:args => ['--verify', sig, file],
:print_stdout => true)
end
end