gpg: cleanup and simplify.
This commit is contained in:
parent
08a452fead
commit
e8fa6f9ad1
@ -1,29 +1,17 @@
|
|||||||
require "utils"
|
require "utils"
|
||||||
|
|
||||||
class Gpg
|
class Gpg
|
||||||
def self.find_gpg(executable)
|
module_function
|
||||||
which_all(executable).detect do |gpg|
|
|
||||||
gpg_short_version = Utils.popen_read(gpg, "--version")[/\d\.\d/, 0]
|
def executable
|
||||||
next unless gpg_short_version
|
which "gpg"
|
||||||
gpg_version = Version.create(gpg_short_version.to_s)
|
|
||||||
@version = gpg_version
|
|
||||||
gpg_version >= Version.create("2.0")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.executable
|
def available?
|
||||||
find_gpg("gpg") || find_gpg("gpg2")
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.available?
|
|
||||||
File.executable?(executable.to_s)
|
File.executable?(executable.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.version
|
def create_test_key(path)
|
||||||
@version if available?
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.create_test_key(path)
|
|
||||||
odie "No GPG present to test against!" unless available?
|
odie "No GPG present to test against!" unless available?
|
||||||
|
|
||||||
(path/"batch.gpg").write <<~EOS
|
(path/"batch.gpg").write <<~EOS
|
||||||
@ -40,8 +28,9 @@ class Gpg
|
|||||||
system executable, "--batch", "--gen-key", "batch.gpg"
|
system executable, "--batch", "--gen-key", "batch.gpg"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cleanup_test_processes!
|
def cleanup_test_processes!
|
||||||
odie "No GPG present to test against!" unless available?
|
odie "No GPG present to test against!" unless available?
|
||||||
|
|
||||||
gpgconf = Pathname.new(executable).parent/"gpgconf"
|
gpgconf = Pathname.new(executable).parent/"gpgconf"
|
||||||
|
|
||||||
system gpgconf, "--kill", "gpg-agent"
|
system gpgconf, "--kill", "gpg-agent"
|
||||||
@ -49,7 +38,7 @@ class Gpg
|
|||||||
"gpg-agent"
|
"gpg-agent"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.test(path)
|
def test(path)
|
||||||
create_test_key(path)
|
create_test_key(path)
|
||||||
begin
|
begin
|
||||||
yield
|
yield
|
||||||
|
Loading…
x
Reference in New Issue
Block a user