forked from zivtech/vagrant-development-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh-add.rb
36 lines (32 loc) · 1.08 KB
/
ssh-add.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# require 'vagrant'
require 'net/ssh'
# TODO: This should actually be tied to `vagrant ssh`. Update for the new API.
# module ZivtechKeyAdder
# class Middleware < Vagrant::Command::SSH
# def initialize(app, env, options = {})
# @app = app
# @env = env
# end
# def execute
# with_target_vms(nil) do |vm|
agent = Net::SSH::Authentication::Agent.connect()
rsaFound = false
agent.identities().each do |identity|
if identity.comment.scan('id_rsa').length == 1
rsaFound = true
end
end
if not rsaFound
# If we are still running, no rsa key was found. Add one
# @env.ui.info "No RSA key found, running ssh-add to add one."
puts "No RSA key found, running ssh-add to add one."
Kernel.system "ssh-add"
end
# Load and call the default SSH command middleware
# sshCommand = Vagrant::Command::SSH.new @app, @env
# sshCommand.execute()
# end
# end
# end
# end
# Vagrant.commands.register(:ssh) { ZivtechKeyAdder::Middleware }