Skip to content

Commit

Permalink
Updating ssh adder code to make it much dumber. Should be ok if you a…
Browse files Browse the repository at this point in the history
…ctually have SSH keys.
  • Loading branch information
tizzo committed Jun 18, 2013
1 parent cc280a4 commit 9f58caf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
8 changes: 6 additions & 2 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)

# Include our deploy command.
# require File.dirname(__FILE__) + '/ssh-add.rb'
if not is_windows
require File.dirname(__FILE__) + '/ssh-add.rb'
end

Vagrant.configure("2") do |config|

Expand All @@ -27,7 +31,7 @@ Vagrant.configure("2") do |config|
end
# NFS sharing does not work on windows, so if this is windows don't try to start it.
require 'rbconfig'
is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)

if not is_windows
config.vm.synced_folder "web", "/var/www", :nfs => true
else
Expand Down
37 changes: 20 additions & 17 deletions ssh-add.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
require 'vagrant'
# require 'vagrant'
require 'net/ssh'

module ZivtechKeyAdder
class Middleware < Vagrant::Command::SSH
def initialize(app, env, options = {})
@app = app
@env = env
end
# TODO: This should actually be tied to `vagrant ssh`. Update for the new API.

def execute
with_target_vms(nil) do |vm|
# 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|
Expand All @@ -19,15 +21,16 @@ def execute
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."
# @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
# sshCommand = Vagrant::Command::SSH.new @app, @env
# sshCommand.execute()
# end
# end
# end
# end

Vagrant.commands.register(:ssh) { ZivtechKeyAdder::Middleware }
# Vagrant.commands.register(:ssh) { ZivtechKeyAdder::Middleware }

0 comments on commit 9f58caf

Please sign in to comment.