vagrant-proxyssh 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -16,14 +16,24 @@ SSH-setup.
16
16
 
17
17
  ## Installation
18
18
 
19
- Either use `vagrant gem`, or add a `gem "vagrant-proxyssh"` to your `Gemfile`.
19
+ Use `vagrant gem install vagrant-proxyssh` if you have a packaged installation of Vagrant.
20
20
 
21
- Before first use, you can run `vagrant proxy-ssh --setup` to add the necessary
21
+ Use `gem install vagrant-proxyssh` if you have Vagrant installed directly as a gem.
22
+
23
+ Use `gem "vagrant-proxyssh"` if you bundle Vagrant in a `Gemfile`.
24
+
25
+ Run `vagrant proxy-ssh --setup` somewhere with an active Vagrant to add the necessary
22
26
  configuration to `~/.ssh/config`.
23
27
 
24
- The setup routine is hard-coded for `rbenv`, and assumes Vagrant is bundled with
25
- each project. Simply modify the `ProxyCommand` line in `~/.ssh/config` if you use
26
- a system-Ruby, or RVM, or have Vagrant installed as a system gem.
28
+ The setup routine assumes your login environment has the right Ruby-version in its path.
29
+
30
+ ### OS X
31
+
32
+ On OS X, your login environment is determined by `~/.MacOSX/environment.plist`, and may
33
+ not reflect what you have in your `.bashrc`, `.zshrc`, or such.
34
+
35
+ Specifically, things may not work with Rubies installed with RVM, rbenv, or Homebrew,
36
+ since none of the usual paths are in the default environment.
27
37
 
28
38
 
29
39
  ## Usage
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ vmname = ARGV[0].sub(/^vagrant-?/, '')
4
+
5
+ port = 0
6
+
7
+ raise "No Vagrant here" unless File.exist?('Vagrantfile')
8
+ raise "No active Vagrant here" unless File.exist?('.vagrant')
9
+
10
+ if ENV['PATH'].split(/:/).any? { |path| File.executable?("#{path}/VBoxManage") }
11
+ require 'json'
12
+ vmname = "default" if vmname == ""
13
+ vms = JSON.load(File.read('.vagrant'))["active"]
14
+ ssh_info = `VBoxManage showvminfo #{vms[vmname]} | grep 'name = ssh'`
15
+ port = ssh_info.match(/host port = (\d+),/)[1]
16
+ else
17
+ cmd = 'bundle exec vagrant'
18
+ cmd = 'vagrant' if ENV['PATH'].split(/:/).any? { |path| File.executable?("#{path}/vagrant") }
19
+ port = `#{cmd} ssh-config #{vmname} | grep Port`.match(/Port (\d+)/)[1]
20
+ end
21
+
22
+ raise "Cannot find port-info for Vagrant host" if port == 0
23
+
24
+ exec "nc", "127.0.0.1", port
@@ -5,45 +5,34 @@ class Vagrant::Command::ProxySSH < Vagrant::Command::Base
5
5
  options = {}
6
6
 
7
7
  opts = OptionParser.new do |opt|
8
- opt.banner = "Usage: <used by ssh>"
9
- opt.separator "Helper used to create fake hostnames that proxy through to a VM"
10
- opt.separator ""
8
+ opt.banner = "Usage: Helper to setup ~/.ssh/config for using vagrant-proxy-ssh"
11
9
 
12
10
  opt.on("-s", "--setup", "Set up magic in ~/.ssh/config") do |o|
13
11
  options[:setup] = o
14
12
  end
15
13
  end
16
14
 
17
- argv = parse_options(opts)
15
+ parse_options(opts)
18
16
 
19
- return if argv[0].nil?
17
+ return unless options[:setup]
20
18
 
21
- vmname = argv[0].sub(/^vagrant-?/, '')
22
- vmname = nil if vmname == ""
23
-
24
- with_target_vms(vmname, :single_target => true) do |vm|
19
+ with_target_vms(nil, :single_target => true) do |vm|
25
20
  raise Errors::VMNotCreatedError if !vm.created?
26
21
  raise Errors::VMInaccessible if !vm.state == :inaccessible
27
22
  raise Errors::VMNotRunningError if vm.state != :running
28
23
 
29
24
  ssh_info = vm.ssh.info
30
25
 
31
- if options[:setup]
32
- File.open(File.expand_path("~/.ssh/config"), 'a') do |file|
33
- file.puts
34
- file.puts "Host vagrant*"
35
- file.puts " ProxyCommand rbenv exec bundle exec vagrant proxy-ssh %h"
36
- file.puts " User #{ssh_info[:username]}"
37
- file.puts " UserKnownHostsFile /dev/null"
38
- file.puts " StrictHostKeyChecking no"
39
- file.puts " PasswordAuthentication no"
40
- file.puts " IdentityFile #{ssh_info[:private_key_path]}"
41
- file.puts " IdentitiesOnly yes"
42
- end
43
- else
44
- raise Errors::SSHPortNotDetected if ssh_info[:port].nil?
45
-
46
- exec 'nc', '127.0.0.1', ssh_info[:port].to_s
26
+ File.open(File.expand_path("~/.ssh/config"), 'a') do |file|
27
+ file.puts
28
+ file.puts "Host vagrant*"
29
+ file.puts " ProxyCommand #{cmd}-proxy-ssh %h"
30
+ file.puts " User #{ssh_info[:username]}"
31
+ file.puts " UserKnownHostsFile /dev/null"
32
+ file.puts " StrictHostKeyChecking no"
33
+ file.puts " PasswordAuthentication no"
34
+ file.puts " IdentityFile #{ssh_info[:private_key_path]}"
35
+ file.puts " IdentitiesOnly yes"
47
36
  end
48
37
  end
49
38
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "vagrant-proxyssh"
5
- s.version = "0.1.1"
5
+ s.version = "0.2.0"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Kenneth Vestergaard"]
8
8
  s.email = ["kvs@binarysolutions.dk"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-proxyssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-21 00:00:00.000000000 Z
12
+ date: 2012-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vagrant
16
- requirement: &70265749390760 !ruby/object:Gem::Requirement
16
+ requirement: &70359647557040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,17 +21,19 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70265749390760
24
+ version_requirements: *70359647557040
25
25
  description: Makes it possible to use 'ssh' to login to a Vagrant VM, without adding
26
26
  multiple fake hosts to ~/.ssh/config
27
27
  email:
28
28
  - kvs@binarysolutions.dk
29
- executables: []
29
+ executables:
30
+ - vagrant-proxy-ssh
30
31
  extensions: []
31
32
  extra_rdoc_files: []
32
33
  files:
33
34
  - LICENSE
34
35
  - README.md
36
+ - bin/vagrant-proxy-ssh
35
37
  - lib/vagrant-proxyssh.rb
36
38
  - lib/vagrant_init.rb
37
39
  - vagrant-proxyssh.gemspec