From d938a30b97b61579b429e471900444902d82f728 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Mon, 8 Jun 2015 06:33:10 -0400 Subject: [PATCH] some ruby stuff to read an ssh file not sure what this is for --- bin/ssh-key-update | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 bin/ssh-key-update diff --git a/bin/ssh-key-update b/bin/ssh-key-update new file mode 100755 index 0000000..76424e8 --- /dev/null +++ b/bin/ssh-key-update @@ -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 +