vagrant-vbguest 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  #!/bin/bash
2
+ apt-get install -y linux-headers-`uname -r` dkms
2
3
  mount /tmp/VBoxGuestAdditions.iso -o loop /mnt
3
4
  /mnt/VBoxLinuxAdditions.run --nox11
4
5
  umount /mnt
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+ mount /tmp/VBoxGuestAdditions.iso -o loop /mnt
3
+ /mnt/VBoxLinuxAdditions.run --nox11
4
+ umount /mnt
@@ -2,6 +2,7 @@ module VagrantVbguest
2
2
 
3
3
  class Command < Vagrant::Command::Base
4
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"
5
6
 
6
7
  # Executes the given rake command on the VMs that are represented
7
8
  # by this environment.
@@ -13,7 +14,7 @@ module VagrantVbguest
13
14
 
14
15
  # Executes a command on a specific VM.
15
16
  def execute_on_vm(vm)
16
- vm.env.actions.run(:vbguest)
17
+ vm.env.actions.run(:vbguest, "vbguest.force.install" => options[:force])
17
18
  end
18
19
  end
19
20
  end
@@ -8,58 +8,76 @@ module VagrantVbguest
8
8
  def initialize(app, env, options = {})
9
9
  @app = app
10
10
  @env = env
11
+ @vm = version = env["vm"]
11
12
  @run_level = options.delete(:run_level)
13
+ @force = options.delete(:force) || env["vbguest.force.install"]
12
14
  end
13
15
 
14
16
  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
17
 
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)
18
+ if shall_run?
29
19
 
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
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))
36
24
 
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
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
41
51
  end
42
-
43
- # Puts out an ending newline just to make sure we end on a new
44
- # line.
45
- $stdout.puts
46
52
  end
47
- else
48
- env.ui.info(I18n.t("vagrant.plugins.vbguest.guest_ok", :version => guest_version))
49
53
  end
50
54
  end
51
-
55
+
52
56
  @app.call(env)
53
57
  end
54
58
 
55
59
  protected
56
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
+
57
70
  def vm_up?
58
- @env["vm"].created? && @env["vm"].vm.running?
71
+ @vm.created? && @env["vm"].vm.running?
59
72
  end
60
73
 
61
74
  def shall_run?
62
- vm_up? && (!@run_level || @env["config"].vbguest.auto_update)
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, '')
63
81
  end
64
82
 
65
83
  def iso_path
@@ -71,7 +89,16 @@ module VagrantVbguest
71
89
  end
72
90
 
73
91
  def installer_script
74
- File.expand_path("../../../files/setup_debian.sh", __FILE__)
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
75
102
  end
76
103
 
77
104
  def installer_destination
@@ -1,3 +1,3 @@
1
1
  module VagrantVbguest
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/locales/en.yml CHANGED
@@ -2,8 +2,11 @@ en:
2
2
  vagrant:
3
3
  plugins:
4
4
  vbguest:
5
- guest_ok: "Guests Virtualbox Guest Additions %{version} --- OK."
5
+ guest_ok: "Detected Virtualbox Guest Additions %{version} --- OK."
6
6
  installing: "Installing Virtualbox Guest Additions %{host} - guest's version is %{guest}"
7
+ installing_forced: "Forcing installation of Virtualbox Guest Additions %{host} - guest's version is %{guest}"
7
8
  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
9
  start_copy_iso: "Copy iso file %{from} into the box %{to}"
9
10
  start_copy_script: "Copy installer file %{from} into the box %{to}"
11
+ no_install_script_for_plattform: "Sorry, not shure how to install on a %{plattform} system. Stopping installation."
12
+ generic_install_script_for_plattform: "%{plattform} is currently not supported, but i'll try generic linux way ... "
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: vagrant-vbguest
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Robert Schulze
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-06 00:00:00 +02:00
13
+ date: 2011-09-19 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -62,6 +62,7 @@ files:
62
62
  - Rakefile
63
63
  - Readme.md
64
64
  - files/setup_debian.sh
65
+ - files/setup_linux.sh
65
66
  - lib/vagrant-vbguest.rb
66
67
  - lib/vagrant-vbguest/command.rb
67
68
  - lib/vagrant-vbguest/config.rb