1
0
Fork 0

some ruby stuff to read an ssh file

not sure what this is for
This commit is contained in:
Andrew Tomaka 2015-06-08 06:33:10 -04:00
parent 5c4658d39e
commit d938a30b97

40
bin/ssh-key-update Executable file
View file

@ -0,0 +1,40 @@
#!/usr/bin/env ruby
require 'pp'
class SSHKey
def initialize(block)
parse(block)
end
private
def parse(block)
pairs = Hash[*block.split("\n").map { |p| p.strip.split(' ') }.flatten]
@Host = pairs.delete('Host')
pairs.each { |key, value| instance_variable_set("@#{key}", value) }
end
end
def retrieve_ssh_keys(config_file)
config = File.new(config_file, 'r')
current = ''
keys = Array.new
config.each_line do |line|
next if line.include?('#')
if line.start_with?('Host')
keys << SSHKey.new(current)
current = ''
end
current += line
end
return keys
end
keys = retrieve_ssh_keys('/home/atomaka/.ssh/config')
pp keys