vagrant-vbguest 0.0.3 → 0.1.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/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
1
  source "http://rubygems.org"
2
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
3
  gemspec
data/Readme.md CHANGED
@@ -4,10 +4,12 @@
4
4
 
5
5
  ## Installation
6
6
 
7
- Requires vagrant 0.8 (well, did not tested on others. feel free)
7
+ Requires vagrant 0.8 (well, did not tested on earlier versions. feel free)
8
8
 
9
9
  gem install vagrant-vbguest
10
-
10
+
11
+ Compatibly for vagrant 0.9 is currently under development and __will drop support for vagrant 0.8__.
12
+
11
13
  ## Configuration / Usage
12
14
 
13
15
  In your `Vagrantfile`:
@@ -1,17 +1,14 @@
1
1
  require 'vagrant'
2
2
  require "vagrant-vbguest/config"
3
+ require "vagrant-vbguest/installer"
3
4
  require 'vagrant-vbguest/command'
4
5
  require 'vagrant-vbguest/middleware'
5
6
 
6
- vbguest = Vagrant::Action::Builder.new do
7
- use VagrantVbguest::Middleware
8
- end
7
+ Vagrant.config_keys.register(:vbguest) { VagrantVbguest::Config }
9
8
 
10
- Vagrant::Action.register(:vbguest, vbguest)
9
+ Vagrant.commands.register(:vbguest) { VagrantVbguest::Command }
11
10
 
12
- [:start, :up, :reload].each do |level|
13
- Vagrant::Action[level].use VagrantVbguest::Middleware, :run_level => level
14
- end
11
+ Vagrant.actions[:start].use VagrantVbguest::Middleware
15
12
 
16
13
  # Add our custom translations to the load path
17
14
  I18n.load_path << File.expand_path("../../locales/en.yml", __FILE__)
@@ -1,20 +1,41 @@
1
+ require 'optparse'
2
+
1
3
  module VagrantVbguest
2
4
 
3
5
  class Command < Vagrant::Command::Base
4
- register "vbguest", "Check and Update the VirtualBox Guest Additions"
5
- class_option :force, :type => :boolean, :required => false, :default => false, :desc => "Whether to force the installation"
6
-
6
+
7
7
  # Executes the given rake command on the VMs that are represented
8
8
  # by this environment.
9
9
  def execute
10
- target_vms.each { |vm| execute_on_vm(vm) }
10
+ options = {}
11
+ opts = OptionParser.new do |opts|
12
+ opts.banner = "Usage: vagrant vbguest [vm-name] [-f|--force]"
13
+ opts.separator ""
14
+
15
+ opts.on("-f", "--force", "Whether to force the installation") do |f|
16
+ options[:force] = f
17
+ end
18
+ end
19
+
20
+ argv = parse_options(opts)
21
+ return if !argv
22
+
23
+ if argv.empty?
24
+ with_target_vms(nil) { |vm| execute_on_vm(vm, options) }
25
+ else
26
+ argv.each do |vm_name|
27
+ with_target_vms(vm_name) { |vm| execute_on_vm(vm, options) }
28
+ end
29
+ end
30
+
11
31
  end
12
32
 
13
33
  protected
14
34
 
15
35
  # Executes a command on a specific VM.
16
- def execute_on_vm(vm)
17
- vm.env.actions.run(:vbguest, "vbguest.force.install" => options[:force])
36
+ def execute_on_vm(vm, options)
37
+ options.merge!(vm.config.vbguest.to_hash)
38
+ VagrantVbguest::Installer.new(vm, options).run!
18
39
  end
19
40
  end
20
- end
41
+ end
@@ -1,7 +1,8 @@
1
+ require 'virtualbox'
2
+
1
3
  module VagrantVbguest
2
4
 
3
5
  class Config < Vagrant::Config::Base
4
- configures :vbguest
5
6
  attr_accessor :iso_path
6
7
  attr_accessor :auto_update
7
8
 
@@ -14,7 +15,14 @@ module VagrantVbguest
14
15
  def validate(errors)
15
16
  errors.add(I18n.t("vagrant.plugins.vbguest.missing_iso_path")) unless iso_path && iso_path.is_a?(String) && File.exists?(iso_path)
16
17
  end
17
-
18
+
19
+ # explicit hash, to get symbols in hash keys
20
+ def to_hash
21
+ {
22
+ :iso_path => iso_path,
23
+ :auto_update => auto_update
24
+ }
25
+ end
18
26
 
19
27
  protected
20
28
 
@@ -25,5 +33,4 @@ module VagrantVbguest
25
33
  @iso_path = dvd.location if dvd
26
34
  end
27
35
  end
28
-
29
- end
36
+ end
@@ -0,0 +1,99 @@
1
+ module VagrantVbguest
2
+
3
+ # Handles the guest addins installation process
4
+
5
+ class Installer
6
+
7
+ def initialize(vm, options = {})
8
+ @vm = vm
9
+ @options = options
10
+ end
11
+
12
+ def run!
13
+ @options[:auto_update] = true
14
+ run
15
+ end
16
+
17
+ def run
18
+ raise Vagrant::Errors::VMNotCreatedError if !@vm.created?
19
+ raise Vagrant::Errors::VMInaccessible if !@vm.state == :inaccessible
20
+ raise Vagrant::Errors::VMNotRunningError if @vm.state != :running
21
+
22
+ if @options[:auto_update]
23
+ @vm.ui.success(I18n.t("vagrant.plugins.vbguest.guest_ok", :version => guest_version)) unless needs_update?
24
+
25
+ if @options[:force] || needs_update?
26
+ @vm.ui.warn(I18n.t("vagrant.plugins.vbguest.installing#{@options[:force] ? '_forced' : ''}", :host => vb_version, :guest => guest_version))
27
+
28
+ # :TODO:
29
+ # the whole installation process should be put into own classes
30
+ # like the vagrant system loading
31
+ if i_script = installer_script
32
+ @vm.ui.info(I18n.t("vagrant.plugins.vbguest.start_copy_iso", :from => iso_path, :to => iso_destination))
33
+ @vm.channel.upload(iso_path, iso_destination)
34
+
35
+ @vm.ui.info(I18n.t("vagrant.plugins.vbguest.start_copy_script", :from => File.basename(i_script), :to => installer_destination))
36
+ @vm.channel.upload(i_script, installer_destination)
37
+
38
+ @vm.channel.sudo("sh #{installer_destination}") do |type, data|
39
+ # Print the data directly to STDOUT, not doing any newlines
40
+ # or any extra formatting of our own
41
+ $stdout.print(data) if type != :exit_status
42
+ end
43
+
44
+ @vm.channel.execute("rm /tmp/install_vbguest.sh /tmp/VBoxGuestAdditions.iso") do |type, data|
45
+ # Print the data directly to STDOUT, not doing any newlines
46
+ # or any extra formatting of our own
47
+ $stdout.print(data) if type != :exit_status
48
+ end
49
+
50
+ # Puts out an ending newline just to make sure we end on a new
51
+ # line.
52
+ $stdout.puts
53
+ end
54
+ end
55
+
56
+ end
57
+ end
58
+
59
+ def needs_update?
60
+ !(guest_version && vb_version == guest_version)
61
+ end
62
+
63
+ def guest_version
64
+ guest_version = @vm.driver.read_guest_additions_version
65
+ !guest_version ? nil : guest_version.gsub(/[-_]ose/i, '')
66
+ end
67
+
68
+ def vb_version
69
+ @vm.driver.version
70
+ end
71
+
72
+ def installer_script
73
+ plattform = @vm.guest.distro_dispatch
74
+ case plattform
75
+ when :debian, :ubuntu
76
+ return File.expand_path("../../../files/setup_debian.sh", __FILE__)
77
+ when :gentoo, :redhat, :suse, :arch, :linux
78
+ @vm.ui.warn(I18n.t("vagrant.plugins.vbguest.generic_install_script_for_plattform", :plattform => plattform.to_s))
79
+ return File.expand_path("../../../files/setup_linux.sh", __FILE__)
80
+ end
81
+ @vm.ui.error(I18n.t("vagrant.plugins.vbguest.no_install_script_for_plattform", :plattform => plattform.to_s))
82
+
83
+ nil
84
+ end
85
+
86
+ def installer_destination
87
+ '/tmp/install_vbguest.sh'
88
+ end
89
+
90
+ def iso_destination
91
+ '/tmp/VBoxGuestAdditions.iso'
92
+ end
93
+
94
+ def iso_path
95
+ @options[:iso_path]
96
+ end
97
+ end
98
+
99
+ end
@@ -8,102 +8,15 @@ module VagrantVbguest
8
8
  def initialize(app, env, options = {})
9
9
  @app = app
10
10
  @env = env
11
- @vm = version = env["vm"]
12
- @run_level = options.delete(:run_level)
13
- @force = options.delete(:force) || env["vbguest.force.install"]
11
+ @vm = env[:vm]
14
12
  end
15
13
 
16
14
  def call(env)
17
-
18
- if shall_run?
19
-
20
- env.ui.confirm(I18n.t("vagrant.plugins.vbguest.guest_ok", :version => guest_version)) unless needs_update?
21
-
22
- if forced_run? || needs_update?
23
- env.ui.warn(I18n.t("vagrant.plugins.vbguest.installing#{forced_run? ? '_forced' : ''}", :host => VirtualBox.version, :guest => guest_version))
24
-
25
- # :TODO:
26
- # the whole istallation process should be put into own classes
27
- # like the vagrant system loading
28
- if i_script = installer_script
29
- env.ui.info(I18n.t("vagrant.plugins.vbguest.start_copy_iso", :from => iso_path, :to => iso_destination))
30
- @vm.ssh.upload!(iso_path, iso_destination)
31
-
32
- env.ui.info(I18n.t("vagrant.plugins.vbguest.start_copy_script", :from => File.basename(i_script), :to => installer_destination))
33
- @vm.ssh.upload!(i_script, installer_destination)
34
-
35
- @vm.ssh.execute do |ssh|
36
- ssh.sudo!("sh /tmp/install_vbguest.sh") do |channel, type, data|
37
- # Print the data directly to STDOUT, not doing any newlines
38
- # or any extra formatting of our own
39
- $stdout.print(data) if type != :exit_status
40
- end
41
-
42
- ssh.exec!("rm /tmp/install_vbguest.sh /tmp/VBoxGuestAdditions.iso") do |channel, type, data|
43
- # Print the data directly to STDOUT, not doing any newlines
44
- # or any extra formatting of our own
45
- $stdout.print(data) if type != :exit_status
46
- end
47
-
48
- # Puts out an ending newline just to make sure we end on a new
49
- # line.
50
- $stdout.puts
51
- end
52
- end
53
- end
54
- end
55
-
15
+ options = @vm.config.vbguest.to_hash
16
+ options[:auto_update] = true if options[:auto_update].nil?
17
+ VagrantVbguest::Installer.new(@vm, options).run
56
18
  @app.call(env)
57
19
  end
58
-
59
- protected
60
-
61
- def forced_run?
62
- @force
63
- end
64
-
65
- def needs_update?
66
- gv = guest_version
67
- !(gv && VirtualBox.version == gv)
68
- end
69
-
70
- def vm_up?
71
- @vm.created? && @env["vm"].vm.running?
72
- end
73
-
74
- def shall_run?
75
- vm_up? && (forced_run? || !@run_level || @env["config"].vbguest.auto_update)
76
- end
77
-
78
- def guest_version
79
- guest_version = @vm.vm.interface.get_guest_property_value("/VirtualBox/GuestAdd/Version")
80
- guest_version.empty? ? nil : guest_version.gsub(/[-_]ose/i, '')
81
- end
82
-
83
- def iso_path
84
- @env["config"].vbguest.iso_path
85
- end
86
-
87
- def iso_destination
88
- '/tmp/VBoxGuestAdditions.iso'
89
- end
90
-
91
- def installer_script
92
- plattform = @env["vm"].system.distro_dispatch
93
- case @env["vm"].system.distro_dispatch
94
- when :debian, :ubuntu
95
- return File.expand_path("../../../files/setup_debian.sh", __FILE__)
96
- when :gentoo, :redhat, :suse, :arch, :linux
97
- @env.ui.error(I18n.t("vagrant.plugins.vbguest.generic_install_script_for_plattform", :plattform => plattform.to_s))
98
- return File.expand_path("../../../files/setup_linux.sh", __FILE__)
99
- end
100
- @env.ui.error(I18n.t("vagrant.plugins.vbguest.no_install_script_for_plattform", :plattform => plattform.to_s))
101
- nil
102
- end
103
-
104
- def installer_destination
105
- '/tmp/install_vbguest.sh'
106
- end
107
20
  end
108
-
109
- end
21
+
22
+ end
@@ -1,3 +1,3 @@
1
1
  module VagrantVbguest
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.license = 'MIT'
12
12
  s.homepage = "https://github.com/dotless-de/vagrant-vbguest"
13
13
  s.summary = %q{A Vagrant plugin to install the VirtualBoxAdditions into the guest VM}
14
- s.description = %q{A Vagrant plugin to install the VirtualBoxAdditions into the guest VM}
14
+ s.description = %q{A Vagrant plugin wich automatically installs the host's VirtualBox Guest Additions on the guest system.}
15
15
 
16
16
  s.required_rubygems_version = ">= 1.3.6"
17
17
  #s.rubyforge_project = "vagrant-vbguest"
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  # s.add_runtime_dependency "rest-client"
22
22
 
23
23
  s.add_dependency "virtualbox", "~> 0.9.1"
24
- s.add_dependency "vagrant", "~> 0.8.2"
24
+ s.add_dependency "vagrant", "~> 0.9.0"
25
25
  s.add_development_dependency "bundler", ">= 1.0.0"
26
26
 
27
27
  s.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -1,61 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: vagrant-vbguest
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
4
5
  prerelease:
5
- version: 0.0.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Robert Schulze
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-09-19 00:00:00 +02:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2012-01-30 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: virtualbox
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70189468584860 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
18
+ requirements:
22
19
  - - ~>
23
- - !ruby/object:Gem::Version
20
+ - !ruby/object:Gem::Version
24
21
  version: 0.9.1
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: vagrant
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70189468584860
25
+ - !ruby/object:Gem::Dependency
26
+ name: vagrant
27
+ requirement: &70189468582520 !ruby/object:Gem::Requirement
31
28
  none: false
32
- requirements:
29
+ requirements:
33
30
  - - ~>
34
- - !ruby/object:Gem::Version
35
- version: 0.8.2
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.0
36
33
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: bundler
40
34
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70189468582520
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70189468582000 !ruby/object:Gem::Requirement
42
39
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
46
43
  version: 1.0.0
47
44
  type: :development
48
- version_requirements: *id003
49
- description: A Vagrant plugin to install the VirtualBoxAdditions into the guest VM
50
- email:
45
+ prerelease: false
46
+ version_requirements: *70189468582000
47
+ description: A Vagrant plugin wich automatically installs the host's VirtualBox Guest
48
+ Additions on the guest system.
49
+ email:
51
50
  - robert@dotless.de
52
51
  executables: []
53
-
54
52
  extensions: []
55
-
56
53
  extra_rdoc_files: []
57
-
58
- files:
54
+ files:
59
55
  - .gitignore
60
56
  - Gemfile
61
57
  - LICENSE
@@ -66,38 +62,35 @@ files:
66
62
  - lib/vagrant-vbguest.rb
67
63
  - lib/vagrant-vbguest/command.rb
68
64
  - lib/vagrant-vbguest/config.rb
65
+ - lib/vagrant-vbguest/installer.rb
69
66
  - lib/vagrant-vbguest/middleware.rb
70
67
  - lib/vagrant-vbguest/version.rb
71
68
  - lib/vagrant_init.rb
72
69
  - locales/en.yml
73
70
  - vagrant-vbguest.gemspec
74
- has_rdoc: true
75
71
  homepage: https://github.com/dotless-de/vagrant-vbguest
76
- licenses:
72
+ licenses:
77
73
  - MIT
78
74
  post_install_message:
79
75
  rdoc_options: []
80
-
81
- require_paths:
76
+ require_paths:
82
77
  - lib
83
- required_ruby_version: !ruby/object:Gem::Requirement
78
+ required_ruby_version: !ruby/object:Gem::Requirement
84
79
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- version: "0"
89
- required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
85
  none: false
91
- requirements:
92
- - - ">="
93
- - !ruby/object:Gem::Version
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
94
89
  version: 1.3.6
95
90
  requirements: []
96
-
97
91
  rubyforge_project:
98
- rubygems_version: 1.6.2
92
+ rubygems_version: 1.8.15
99
93
  signing_key:
100
94
  specification_version: 3
101
95
  summary: A Vagrant plugin to install the VirtualBoxAdditions into the guest VM
102
96
  test_files: []
103
-