Skip to content

Instantly share code, notes, and snippets.

@txus
Created January 9, 2014 15:50
Show Gist options
  • Save txus/8336323 to your computer and use it in GitHub Desktop.
Save txus/8336323 to your computer and use it in GitHub Desktop.
nifty nice yeah
#!/usr/bin/env ruby
require 'open-uri'
abort("Usage: pgpkey [[email protected]|emails.txt]") unless ARGV.first
emails = if File.exist?(ARGV.first)
File.readlines(ARGV.first).map(&:chomp)
elsif ARGV.first =~ /@/
[ARGV.first]
end
emails.each do |email|
begin
lines = open("http://pgp.mit.edu:11371/pks/lookup?search=#{URI.encode(email)}&op=index").readlines
p lines
id = lines.reject { |line|
line =~ /REVOKED/
}.select { |line|
line =~ /pks\/lookup/
}.each { |l|
p l
}.first.scan(/([A-Z0-9]+)<\/a>/).flatten.first
puts "Found key #{id} for #{ARGV.first}."
`gpg --recv-keys #{id}`
rescue
puts "Didn't find any key for #{ARGV.first}."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment