vagrant-vbguest 0.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,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in vagrant-rake.gemspec
4
+ # gem "vagrant-vbguest", :path => "."
5
+ #
6
+ # gem "vagrant", "~> 0.8.0"
7
+
8
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Robert Schulze <robert@dotless.de>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Readme.md ADDED
@@ -0,0 +1,32 @@
1
+ # vagrant-vbguest
2
+
3
+ `vagrant-vbguest` is a [Vagrant](http://vagrantup.com) plugin wich automatically installes the host's VirtualBox Guest Additions on the guest system.
4
+
5
+ ## Installation
6
+
7
+ Requires vagrant 0.8 (well, did not tested on others. feel free)
8
+
9
+ gem install vagrant-vbguest
10
+
11
+ ## Configuration / Usage
12
+
13
+ In your `Vagrantfile`:
14
+
15
+ Vagrant::Config.run do |config|
16
+ # we will try to autodetect this path.
17
+ # However, if we cannot or you have a special one you may pass it here
18
+ config.vbguest.iso_path = '/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso'
19
+
20
+ # set auto_update to false, if do NOT want to check the correct additions
21
+ # version on each 'vagrant up' (default: true)
22
+ config.vbguest.auto_update = false
23
+ end
24
+
25
+ You may also run the installer manually:
26
+
27
+ $ vagrant vbguest
28
+
29
+ ## Knows Issues
30
+
31
+ * The installer script, which mounts and runs the GuestAdditions Installer Binary, works on linux only. Most likely it will run on most unix-like plattform.
32
+ * The installer script requires a directory `/mnt` on the host system
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ mount /tmp/VBoxGuestAdditions.iso -o loop /mnt
3
+ /mnt/VBoxLinuxAdditions.run --nox11
4
+ umount /mnt
@@ -0,0 +1,17 @@
1
+ require 'vagrant'
2
+ require "vagrant-vbguest/config"
3
+ require 'vagrant-vbguest/command'
4
+ require 'vagrant-vbguest/middleware'
5
+
6
+ vbguest = Vagrant::Action::Builder.new do
7
+ use VagrantVbguest::Middleware
8
+ end
9
+
10
+ Vagrant::Action.register(:vbguest, vbguest)
11
+
12
+ [:start, :up, :reload].each do |level|
13
+ Vagrant::Action[level].use VagrantVbguest::Middleware, :run_level => level
14
+ end
15
+
16
+ # Add our custom translations to the load path
17
+ I18n.load_path << File.expand_path("../../locales/en.yml", __FILE__)
@@ -0,0 +1,19 @@
1
+ module VagrantVbguest
2
+
3
+ class Command < Vagrant::Command::Base
4
+ register "vbguest", "Check and Update the VirtualBox Guest Additions"
5
+
6
+ # Executes the given rake command on the VMs that are represented
7
+ # by this environment.
8
+ def execute
9
+ target_vms.each { |vm| execute_on_vm(vm) }
10
+ end
11
+
12
+ protected
13
+
14
+ # Executes a command on a specific VM.
15
+ def execute_on_vm(vm)
16
+ vm.env.actions.run(:vbguest)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,29 @@
1
+ module VagrantVbguest
2
+
3
+ class Config < Vagrant::Config::Base
4
+ configures :vbguest
5
+ attr_accessor :iso_path
6
+ attr_accessor :auto_update
7
+
8
+ def initialize
9
+ super
10
+ @auto_update = true
11
+ autodetect_iso!
12
+ end
13
+
14
+ def validate(errors)
15
+ errors.add(I18n.t("vagrant.plugins.vbguest.missing_iso_path")) unless iso_path && iso_path.is_a?(String) && File.exists?(iso_path)
16
+ end
17
+
18
+
19
+ protected
20
+
21
+ def autodetect_iso!
22
+ dvd = VirtualBox::DVD.all.find do |d|
23
+ !!(d.location =~ /VBoxGuestAdditions.iso$/)
24
+ end
25
+ @iso_path = dvd.location if dvd
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,82 @@
1
+ module VagrantVbguest
2
+
3
+ # A Vagrant middleware which checks the installed VirtualBox Guest
4
+ # Additions to match the installed VirtualBox installation on the
5
+ # host system.
6
+
7
+ class Middleware
8
+ def initialize(app, env, options = {})
9
+ @app = app
10
+ @env = env
11
+ @run_level = options.delete(:run_level)
12
+ end
13
+
14
+ def call(env)
15
+
16
+ if shall_run?
17
+ version = env["vm"].vm.interface.get_guest_property_value("/VirtualBox/GuestAdd/Version")
18
+ guest_version = version.empty?() ? I18n.t("vagrant.plugins.vbguest.additions_missing_on_guest") : version.gsub(/[-_]ose/i, '');
19
+ needs_update = version.empty? || (VirtualBox.version != guest_version)
20
+
21
+ if needs_update
22
+ env.ui.warn(I18n.t("vagrant.plugins.vbguest.installing", :host => VirtualBox.version, :guest => guest_version))
23
+
24
+ env.ui.info(I18n.t("vagrant.plugins.vbguest.start_copy_iso", :from => iso_path, :to => iso_destination))
25
+ env["vm"].ssh.upload!(iso_path, iso_destination)
26
+
27
+ env.ui.info(I18n.t("vagrant.plugins.vbguest.start_copy_script", :from => File.basename(installer_script), :to => installer_destination))
28
+ env["vm"].ssh.upload!(installer_script, installer_destination)
29
+
30
+ env["vm"].ssh.execute do |ssh|
31
+ ssh.sudo!("sh /tmp/install_vbguest.sh") do |channel, type, data|
32
+ # Print the data directly to STDOUT, not doing any newlines
33
+ # or any extra formatting of our own
34
+ $stdout.print(data) if type != :exit_status
35
+ end
36
+
37
+ ssh.exec!("rm /tmp/install_vbguest.sh /tmp/VBoxGuestAdditions.iso") do |channel, type, data|
38
+ # Print the data directly to STDOUT, not doing any newlines
39
+ # or any extra formatting of our own
40
+ $stdout.print(data) if type != :exit_status
41
+ end
42
+
43
+ # Puts out an ending newline just to make sure we end on a new
44
+ # line.
45
+ $stdout.puts
46
+ end
47
+ else
48
+ env.ui.info(I18n.t("vagrant.plugins.vbguest.guest_ok", :version => guest_version))
49
+ end
50
+ end
51
+
52
+ @app.call(env)
53
+ end
54
+
55
+ protected
56
+
57
+ def vm_up?
58
+ @env["vm"].created? && @env["vm"].vm.running?
59
+ end
60
+
61
+ def shall_run?
62
+ vm_up? && (!@run_level || @env["config"].vbguest.auto_update)
63
+ end
64
+
65
+ def iso_path
66
+ @env["config"].vbguest.iso_path
67
+ end
68
+
69
+ def iso_destination
70
+ '/tmp/VBoxGuestAdditions.iso'
71
+ end
72
+
73
+ def installer_script
74
+ File.expand_path("../../../files/setup_debian.sh", __FILE__)
75
+ end
76
+
77
+ def installer_destination
78
+ '/tmp/install_vbguest.sh'
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,3 @@
1
+ module VagrantVbguest
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,3 @@
1
+ # This file is automatically loaded by Vagrant to load any
2
+ # plugins. This file kicks off this plugin.
3
+ require 'vagrant-vbguest'
data/locales/en.yml ADDED
@@ -0,0 +1,9 @@
1
+ en:
2
+ vagrant:
3
+ plugins:
4
+ vbguest:
5
+ guest_ok: "Guests Virtualbox Guest Additions %{version} --- OK."
6
+ installing: "Installing Virtualbox Guest Additions %{host} - guest's version is %{guest}"
7
+ missing_iso_path: "Could not autodetect the correct location of the Virtualbox Guest Additions ISO File. Or the Path provided is not correct. \nPlease configure using `config.vbguest.iso_path`. \nOn Mac this is most likely: '/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso' "
8
+ start_copy_iso: "Copy iso file %{from} into the box %{to}"
9
+ start_copy_script: "Copy installer file %{from} into the box %{to}"
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "vagrant-vbguest/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "vagrant-vbguest"
7
+ s.version = VagrantVbguest::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Robert Schulze"]
10
+ s.email = ["robert@dotless.de"]
11
+ #s.homepage = "http://rubygems.org/gems/vagrant-vbguest"
12
+ s.summary = %q{A Vagrant plugin to install the VirtualBoxAdditions into the VM}
13
+ s.description = %q{A Vagrant plugin to install the VirtualBoxAdditions into the VM}
14
+
15
+ s.required_rubygems_version = ">= 1.3.6"
16
+ #s.rubyforge_project = "vagrant-vbguest"
17
+
18
+ # specify any dependencies here; for example:
19
+ # s.add_development_dependency "rspec"
20
+ # s.add_runtime_dependency "rest-client"
21
+
22
+ s.add_dependency "virtualbox", "~> 0.9.1"
23
+ s.add_dependency "vagrant", "~> 0.8.2"
24
+ s.add_development_dependency "bundler", ">= 1.0.0"
25
+
26
+ s.files = `git ls-files`.split("\n")
27
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
28
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
29
+ s.require_paths = ["lib"]
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-vbguest
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Robert Schulze
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-06 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: virtualbox
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 0.9.1
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: vagrant
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 0.8.2
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 1.0.0
47
+ type: :development
48
+ version_requirements: *id003
49
+ description: A Vagrant plugin to install the VirtualBoxAdditions into the VM
50
+ email:
51
+ - robert@dotless.de
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - Gemfile
61
+ - LICENSE
62
+ - Rakefile
63
+ - Readme.md
64
+ - files/setup_debian.sh
65
+ - lib/vagrant-vbguest.rb
66
+ - lib/vagrant-vbguest/command.rb
67
+ - lib/vagrant-vbguest/config.rb
68
+ - lib/vagrant-vbguest/middleware.rb
69
+ - lib/vagrant-vbguest/version.rb
70
+ - lib/vagrant_init.rb
71
+ - locales/en.yml
72
+ - vagrant-vbguest.gemspec
73
+ has_rdoc: true
74
+ homepage:
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options: []
79
+
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: 1.3.6
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.6.2
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: A Vagrant plugin to install the VirtualBoxAdditions into the VM
101
+ test_files: []
102
+