vagrant-host-path 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-host-path.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 MOZGIII
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # Vagrant::HostPath
2
+
3
+ This plugin creates an environment variable (`VAGRANT_HOST_PATH` by default) with the path to the project's root dir on your host machine.
4
+ You can just replace `/vagrant` prefix of any file in your VM with the value of `VAGRANT_HOST_PATH` and you'll get the path to that same file on the host.
5
+
6
+ ## Installation
7
+
8
+ If you're using Vagrant with ruby's gem:
9
+
10
+ $ gem install vagrant-host-path
11
+
12
+ Or if you installed it with an installer:
13
+
14
+ $ vagrant gem install vagrant-host-path
15
+
16
+ ## Usage
17
+
18
+ $ vagrant up
19
+ [default] VM already created. Booting if it's not already running...
20
+ ...
21
+ [default] Host Path set!
22
+ ...
23
+ $ vagrant ssh # or any other way you connect to the VM
24
+
25
+ And after that you can use the env var within your VM:
26
+
27
+ Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
28
+
29
+ * Documentation: https://help.ubuntu.com/
30
+ Welcome to your Vagrant-built virtual machine.
31
+ Last login: Tue Feb 26 23:22:00 2013 from 10.0.2.2
32
+ vagrant@precise32:~$ echo $VAGRANT_HOST_PATH
33
+ C:/Users/MOZGIII/Desktop/vagrant-host-path/test
34
+
35
+ ## Configuration
36
+
37
+ ```ruby
38
+ Vagrant::Config.run do |config|
39
+
40
+ # The environment key to set
41
+ config.host-path.env_key = "VAGRANT_HOST_PATH"
42
+
43
+ # Temp file to save path to
44
+ config.host-path.path_file = "/tmp/.vagrant-host-path"
45
+
46
+ # Profile script path
47
+ config.host-path.profile_path = "/etc/profile.d/vagrant-host-path.sh"
48
+ end
49
+ ```
50
+
51
+ Have in mind that both the files get overwritten on every VM start.
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ require "vagrant-host-path/version"
2
+ require "vagrant-host-path/config"
3
+ require "vagrant-host-path/middleware"
4
+
5
+ Vagrant.config_keys.register(:host_path) { Vagrant::HostPath::Config }
6
+ Vagrant.actions[:start].use Vagrant::HostPath::Middleware
@@ -0,0 +1,26 @@
1
+ module Vagrant
2
+ module HostPath
3
+ class Config < Vagrant::Config::Base
4
+ attr_writer :env_key
5
+ attr_writer :path_file
6
+ attr_writer :profile_path
7
+ attr_writer :temp_upload_path
8
+
9
+ def env_key
10
+ @env_key || "VAGRANT_HOST_PATH"
11
+ end
12
+
13
+ def path_file
14
+ @path_file || "/tmp/.vagrant-host-path"
15
+ end
16
+
17
+ def profile_path
18
+ @profile_path || "/etc/profile.d/vagrant-host-path.sh"
19
+ end
20
+
21
+ def temp_upload_path
22
+ @temp_upload_path || "/tmp/vagrant-host-path-profile.sh"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ module Vagrant
2
+ module HostPath
3
+ class Middleware
4
+ def initialize(app, env)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ setup env[:vm] if env[:vm].state == :running
10
+ @app.call(env)
11
+ end
12
+
13
+ protected
14
+
15
+ def setup(vm)
16
+ put_path_file(vm)
17
+ put_profile_file(vm)
18
+ vm.ui.success "Host Path set!"
19
+ end
20
+
21
+ def put_path_file(vm)
22
+ vm.channel.sudo("echo \"#{vm.env.cwd.to_s}\" > \"#{vm.config.host_path.path_file}\"")
23
+ end
24
+
25
+ def put_profile_file(vm)
26
+ content = profile_file(vm.config.host_path)
27
+ vm.channel.sudo("echo \"#{content.gsub(/["`\\]/, '\\\\\0')}\" > \"#{vm.config.host_path.profile_path}\"")
28
+ end
29
+
30
+ def profile_file(config)
31
+ "[ -f \"#{config.path_file}\" ] && export #{config.env_key}=\`cat \"#{config.path_file}\"\`"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module HostPath
3
+ VERSION = "1.0.1"
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ require "vagrant-host-path"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-host-path/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "vagrant-host-path"
8
+ gem.version = Vagrant::HostPath::VERSION
9
+ gem.authors = ["MOZGIII"]
10
+ gem.email = ["mike-n@narod.ru"]
11
+ gem.description = %q{Vagrant plugin that stores the host path to your project in the environment variable in the VM.}
12
+ gem.summary = %q{The host path to your project in the environment variable in the VM for Vagrant.}
13
+ gem.homepage = "https://github.com/MOZGIII/vagrant-host-path"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "vagrant", "~> 1.0.7"
21
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-host-path
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - MOZGIII
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vagrant
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.7
30
+ description: Vagrant plugin that stores the host path to your project in the environment
31
+ variable in the VM.
32
+ email:
33
+ - mike-n@narod.ru
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - lib/vagrant-host-path.rb
44
+ - lib/vagrant-host-path/config.rb
45
+ - lib/vagrant-host-path/middleware.rb
46
+ - lib/vagrant-host-path/version.rb
47
+ - lib/vagrant_init.rb
48
+ - vagrant-host-path.gemspec
49
+ homepage: https://github.com/MOZGIII/vagrant-host-path
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: The host path to your project in the environment variable in the VM for Vagrant.
73
+ test_files: []
74
+ has_rdoc: