module Configure def self.read() begin config = {} File.open(path, 'r') do |file| file.each do |row| row.chomp! cols = row.split(/\s+=\s+/) config[cols[0].to_sym] = cols[1] end end rescue config = {} ensure return config end end def self.write(config) File.open(path, 'w') do |file| config.each do |key, value| file.puts "#{key} = #{value}" end end end def self.init config = self.read output = < 0 config[:use_key] = keys[use_key-1]['name'] else config[:use_key] ||= 'id_rsa' print "Key name (#{config[:use_key]}): " stdin = STDIN.gets.chomp.to_s config[:use_key] = stdin if !stdin.empty? rsa_path = File.join(ENV["HOME"], '/.ssh/id_rsa.pub') print "Public key path (#{rsa_path}): " stdin = STDIN.gets.chomp.to_s rsa_path = stdin if !stdin.empty? end config[:rsa_path] ||= File.join(ENV["HOME"], '/.ssh/id_rsa') print "Private key path (#{config[:rsa_path]}): " stdin = STDIN.gets.chomp.to_s config[:rsa_path] = stdin if !stdin.empty? puts self.write config rsa_path end private def path config = '.sdccfg' file = File.join(File.dirname(__FILE__), '..', config) if File.exist?(file) file else File.join(ENV["HOME"], config) end end end