vagrant-vbguest 0.6.0.pre0 → 0.6.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +25 -0
- data/lib/vagrant-vbguest.rb +11 -4
- data/lib/vagrant-vbguest/command.rb +3 -2
- data/lib/vagrant-vbguest/helpers.rb +0 -42
- data/lib/vagrant-vbguest/installer.rb +82 -65
- data/lib/vagrant-vbguest/installers/base.rb +177 -0
- data/lib/vagrant-vbguest/installers/debian.rb +39 -0
- data/lib/vagrant-vbguest/installers/linux.rb +64 -0
- data/lib/vagrant-vbguest/installers/ubuntu.rb +12 -0
- data/lib/vagrant-vbguest/middleware.rb +4 -3
- data/lib/vagrant-vbguest/version.rb +1 -1
- data/locales/en.yml +8 -2
- metadata +6 -2
data/Readme.md
CHANGED
@@ -52,6 +52,7 @@ vbguest will try to autodetect the best option for your system. WTF? see below.
|
|
52
52
|
* `auto_reboot` (Boolean, dafult: `true` when running as a middleware, `false` when running as a command) : Whether to reboot the box after GuestAdditions has been installed, but not loaded.
|
53
53
|
* `no_install` (Boolean, default: `false`) : Whether to check the correct additions version only. This will warn you about version mis-matches, but will not try to install anything.
|
54
54
|
* `no_remote` (Boolean, default: `false`) : Whether to _not_ download the iso file from a remote location. This includes any `http` location!
|
55
|
+
* `installer` (`VagrantVbguest::Installers::Base`, optional) : Reference to a (custom) installer class
|
55
56
|
|
56
57
|
#### Global Configuration
|
57
58
|
|
@@ -185,6 +186,30 @@ The VirtualBox GuestAdditions Installer will try to load the newly build kernel
|
|
185
186
|
Hency, vbguest will check for a loaded kernel module after the installation has finished and reboots the box, if it could not find one.
|
186
187
|
|
187
188
|
|
189
|
+
## Advanced Usage
|
190
|
+
|
191
|
+
vagrant-vbguest provides installers for generic linux and debian/ubuntu.
|
192
|
+
Installers take care of the whole installation process, that includes where to save the iso file inside the guest and where to mount it.
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
class MyInstaller < VagrantVbguest::Installers::Linux
|
196
|
+
# use /temp instead of /tmp
|
197
|
+
def tmp_path
|
198
|
+
'/temp/VBoxGuestAdditions.iso'
|
199
|
+
end
|
200
|
+
|
201
|
+
# use /media instead of /mnt
|
202
|
+
def mount_point
|
203
|
+
'/media'
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
Vagrant::Config.run do |config|
|
208
|
+
config.vbguest.installer = MyInstaller
|
209
|
+
end
|
210
|
+
```
|
211
|
+
|
212
|
+
|
188
213
|
## Knows Issues
|
189
214
|
|
190
215
|
* 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.
|
data/lib/vagrant-vbguest.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
require 'vagrant'
|
2
2
|
require "vagrant-vbguest/errors"
|
3
|
-
require
|
4
|
-
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require 'vagrant-vbguest/helpers'
|
4
|
+
|
5
|
+
require 'vagrant-vbguest/installer'
|
6
|
+
require 'vagrant-vbguest/installers/base'
|
7
|
+
require 'vagrant-vbguest/installers/linux'
|
8
|
+
require 'vagrant-vbguest/installers/debian'
|
9
|
+
require 'vagrant-vbguest/installers/ubuntu'
|
10
|
+
|
11
|
+
require 'vagrant-vbguest/config'
|
7
12
|
require 'vagrant-vbguest/command'
|
8
13
|
require 'vagrant-vbguest/middleware'
|
9
14
|
|
15
|
+
require 'vagrant-vbguest/download'
|
16
|
+
|
10
17
|
Vagrant.config_keys.register(:vbguest) { VagrantVbguest::Config }
|
11
18
|
|
12
19
|
Vagrant.commands.register(:vbguest) { VagrantVbguest::Command }
|
@@ -58,8 +58,9 @@ module VagrantVbguest
|
|
58
58
|
# Executes a command on a specific VM.
|
59
59
|
def execute_on_vm(vm, options)
|
60
60
|
options = vm.config.vbguest.to_hash.merge(options)
|
61
|
-
VagrantVbguest::Installer.new(vm, options)
|
62
|
-
|
61
|
+
installer = VagrantVbguest::Installer.new(vm, options)
|
62
|
+
installer.run!
|
63
|
+
reboot(vm, options) if installer.need_reboot?
|
63
64
|
end
|
64
65
|
|
65
66
|
def reboot vm, options
|
@@ -1,43 +1,5 @@
|
|
1
1
|
module VagrantVbguest
|
2
2
|
module Helpers
|
3
|
-
class << self
|
4
|
-
|
5
|
-
def local_iso_path_for(vm, options = nil)
|
6
|
-
options ||= {}
|
7
|
-
@local_iso_paths ||= Hash.new
|
8
|
-
@local_iso_paths[vm.uuid] ||= media_manager_iso(vm) || guess_iso(vm)
|
9
|
-
end
|
10
|
-
|
11
|
-
def web_iso_path_for(vm, options = nil)
|
12
|
-
options ||= {}
|
13
|
-
"http://download.virtualbox.org/virtualbox/$VBOX_VERSION/VBoxGuestAdditions_$VBOX_VERSION.iso"
|
14
|
-
end
|
15
|
-
|
16
|
-
def media_manager_iso(vm)
|
17
|
-
(m = vm.driver.execute('list', 'dvds').match(/^.+:\s+(.*VBoxGuestAdditions.iso)$/i)) && m[1]
|
18
|
-
end
|
19
|
-
|
20
|
-
def guess_iso(vm)
|
21
|
-
path_platform = if Vagrant::Util::Platform.linux?
|
22
|
-
"/usr/share/virtualbox/VBoxGuestAdditions.iso"
|
23
|
-
elsif Vagrant::Util::Platform.darwin?
|
24
|
-
"/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"
|
25
|
-
elsif Vagrant::Util::Platform.windows?
|
26
|
-
if (p = ENV["VBOX_INSTALL_PATH"]) && !p.empty?
|
27
|
-
File.join(p, "VBoxGuestAdditions.iso")
|
28
|
-
else
|
29
|
-
File.join((ENV["PROGRAM_FILES"] || ENV["ProgramW6432"] || ENV["PROGRAMFILES"]), "/Oracle/VirtualBox/VBoxGuestAdditions.iso")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
File.exists?(path_platform) ? path_platform : nil
|
33
|
-
end
|
34
|
-
|
35
|
-
def kernel_module_running?(vm, &block)
|
36
|
-
vm.channel.test('lsmod | grep vboxsf', :sudo => true, &block)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
3
|
module Rebootable
|
42
4
|
@@rebooted = {}
|
43
5
|
|
@@ -45,10 +7,6 @@ module VagrantVbguest
|
|
45
7
|
!!@@rebooted[vm.name]
|
46
8
|
end
|
47
9
|
|
48
|
-
def need_reboot?(vm)
|
49
|
-
!VagrantVbguest::Helpers.kernel_module_running?(vm)
|
50
|
-
end
|
51
|
-
|
52
10
|
def reboot(vm, options)
|
53
11
|
if options[:auto_reboot]
|
54
12
|
vm.ui.warn(I18n.t("vagrant.plugins.vbguest.restart_vm"))
|
@@ -4,6 +4,47 @@ module VagrantVbguest
|
|
4
4
|
|
5
5
|
class Installer
|
6
6
|
|
7
|
+
class NoInstallerFoundError < Vagrant::Errors::VagrantError
|
8
|
+
error_namespace "vagrant.plugins.vbguest.errors.installer"
|
9
|
+
error_key "no_install_script_for_platform"
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
|
14
|
+
##
|
15
|
+
# Register an Installer implementation.
|
16
|
+
# All Installer classes which wish to get picked automaticly
|
17
|
+
# using their `#match?` method have to register.
|
18
|
+
# Ad-hoc or small custom Installer meight not need to get
|
19
|
+
# registered, but need to get passed as an config option (`installer`)
|
20
|
+
#
|
21
|
+
# Registration takes a priority which defines how specific
|
22
|
+
# the Installer matches a system. Low level installers, like
|
23
|
+
# "linux" or "bsd" use a small priority (2), while distribution
|
24
|
+
# installers use higher priority (5). Installers matching a
|
25
|
+
# specific version of a distribution should use heigher
|
26
|
+
# priority numbers.
|
27
|
+
#
|
28
|
+
# @param [Class] installer_class A reference to the Installer class.
|
29
|
+
# @param [Fixnum] prio Priority describing how specific the Installer matches. (default: `5`)
|
30
|
+
def register(installer_class, prio = 5)
|
31
|
+
@installers ||= {}
|
32
|
+
@installers[prio] ||= []
|
33
|
+
@installers[prio] << installer_class
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Returns an instance of the registrated Installer class which
|
38
|
+
# matches first (according to it's priority) or `nil` if none matches.
|
39
|
+
def detect(vm, options)
|
40
|
+
@installers.keys.sort.reverse.each do |prio|
|
41
|
+
klass = @installers[prio].detect { |k| k.match?(vm) }
|
42
|
+
return klass.new(vm, options) if klass
|
43
|
+
end
|
44
|
+
return nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
7
48
|
def initialize(vm, options = {})
|
8
49
|
@env = {
|
9
50
|
:ui => vm.ui,
|
@@ -20,7 +61,6 @@ module VagrantVbguest
|
|
20
61
|
end
|
21
62
|
|
22
63
|
def run
|
23
|
-
|
24
64
|
return unless @options[:auto_update]
|
25
65
|
|
26
66
|
raise Vagrant::Errors::VMNotCreatedError if !@vm.created?
|
@@ -39,36 +79,46 @@ module VagrantVbguest
|
|
39
79
|
end
|
40
80
|
|
41
81
|
def install
|
42
|
-
|
43
|
-
|
44
|
-
# like the vagrant system loading
|
45
|
-
if (i_script = installer_script)
|
46
|
-
@vm.ui.info(I18n.t("vagrant.plugins.vbguest.start_copy_iso", :from => iso_path, :to => iso_destination))
|
47
|
-
@vm.channel.upload(iso_path, iso_destination)
|
48
|
-
|
49
|
-
@vm.ui.info(I18n.t("vagrant.plugins.vbguest.start_copy_script", :from => File.basename(i_script), :to => installer_destination))
|
50
|
-
@vm.channel.upload(i_script, installer_destination)
|
51
|
-
|
52
|
-
@vm.channel.sudo("chmod 0755 #{installer_destination}") do |type, data|
|
53
|
-
@vm.ui.info(data, :prefix => false, :new_line => false)
|
54
|
-
end
|
82
|
+
installer = guest_installer
|
83
|
+
raise NoInstallerFoundError, :method => 'install' if !installer
|
55
84
|
|
56
|
-
|
57
|
-
|
58
|
-
|
85
|
+
# @vm.ui.info "Installing using #{installer.class.to_s}"
|
86
|
+
installer.install do |type, data|
|
87
|
+
@vm.ui.info(data, :prefix => false, :new_line => false)
|
88
|
+
end
|
89
|
+
end
|
59
90
|
|
60
|
-
|
61
|
-
|
62
|
-
|
91
|
+
def rebuild
|
92
|
+
installer = guest_installer
|
93
|
+
raise NoInstallerFoundError, :method => 'rebuild' if !installer
|
63
94
|
|
64
|
-
|
95
|
+
installer.rebuild do |type, data|
|
96
|
+
@vm.ui.info(data, :prefix => false, :new_line => false)
|
65
97
|
end
|
66
98
|
end
|
67
99
|
|
100
|
+
def needs_rebuild?
|
101
|
+
installer = guest_installer
|
102
|
+
raise NoInstallerFoundError, :method => 'check installation of' if !installer
|
103
|
+
|
104
|
+
installer.needs_rebuild?
|
105
|
+
end
|
106
|
+
|
107
|
+
def need_reboot?
|
108
|
+
installer = guest_installer
|
109
|
+
raise NoInstallerFoundError, :method => 'check installation of' if !installer
|
110
|
+
|
111
|
+
installer.need_reboot?
|
112
|
+
end
|
113
|
+
|
68
114
|
def needs_update?
|
69
115
|
!(guest_version && vb_version == guest_version)
|
70
116
|
end
|
71
117
|
|
118
|
+
##
|
119
|
+
#
|
120
|
+
# @return [String] The version code of the VirtualBox Guest Additions
|
121
|
+
# available on the guest, or `nil` if none installed.
|
72
122
|
def guest_version
|
73
123
|
return @guest_version if @guest_version
|
74
124
|
|
@@ -85,59 +135,26 @@ module VagrantVbguest
|
|
85
135
|
@guest_version = guest_version
|
86
136
|
end
|
87
137
|
|
138
|
+
# Returns the version code of the Virtual Box *host*
|
88
139
|
def vb_version
|
89
140
|
@vm.driver.version
|
90
141
|
end
|
91
142
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
143
|
+
# Returns an installer instance for the current vm
|
144
|
+
# This is either the one configured via `installer` option or
|
145
|
+
# detected from all registered installers (see {Installer.detect})
|
146
|
+
#
|
147
|
+
# @return [Installers::Base]
|
148
|
+
def guest_installer
|
149
|
+
@guest_installer ||= if @options[:installer].is_a? Class
|
150
|
+
@options[:installer].new(@vm)
|
100
151
|
else
|
101
|
-
@vm
|
102
|
-
nil
|
152
|
+
Installer.detect(@vm, @options)
|
103
153
|
end
|
104
154
|
end
|
105
155
|
|
106
|
-
def installer_destination
|
107
|
-
'/tmp/install_vbguest.sh'
|
108
|
-
end
|
109
|
-
|
110
|
-
def iso_destination
|
111
|
-
'/tmp/VBoxGuestAdditions.iso'
|
112
|
-
end
|
113
|
-
|
114
|
-
def iso_path
|
115
|
-
@iso_path ||= begin
|
116
|
-
@options[:iso_path] ||= VagrantVbguest::Helpers.local_iso_path_for @vm, @options
|
117
|
-
if !@options[:iso_path] || @options[:iso_path].empty? && !@options[:no_remote]
|
118
|
-
@options[:iso_path] = VagrantVbguest::Helpers.web_iso_path_for @vm, @options
|
119
|
-
end
|
120
|
-
raise VagrantVbguest::IsoPathAutodetectionError if !@options[:iso_path] || @options[:iso_path].empty?
|
121
|
-
@env[:iso_url] ||= @options[:iso_path].gsub '$VBOX_VERSION', vb_version
|
122
|
-
|
123
|
-
if local_iso?
|
124
|
-
@env[:iso_url]
|
125
|
-
else
|
126
|
-
# :TODO: This will also raise, if the iso_url points to an invalid local path
|
127
|
-
raise VagrantVbguest::DownloadingDisabledError.new(:from => @env[:iso_url]) if @options[:no_remote]
|
128
|
-
@download = VagrantVbguest::Download.new(@env)
|
129
|
-
@download.download
|
130
|
-
@download.temp_path
|
131
|
-
end
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
def local_iso?
|
136
|
-
::File.file?(@env[:iso_url])
|
137
|
-
end
|
138
|
-
|
139
156
|
def cleanup
|
140
|
-
@
|
157
|
+
@guest_installer.cleanup if @guest_installer
|
141
158
|
end
|
142
159
|
|
143
160
|
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
module VagrantVbguest
|
2
|
+
module Installers
|
3
|
+
class Error < Vagrant::Errors::VagrantError
|
4
|
+
error_namespace "vagrant.plugins.vbguest.errors.installer"
|
5
|
+
end
|
6
|
+
|
7
|
+
# This is the base class all installers must inherit from
|
8
|
+
# It defines the basic structure of an Installer and should
|
9
|
+
# never be used directly
|
10
|
+
class Base
|
11
|
+
|
12
|
+
# Tests whether this installer class is applicable to the
|
13
|
+
# current environment. Usually, testing for a specific OS.
|
14
|
+
# Subclasses must override this method and return `true` if
|
15
|
+
# they wish to handle.
|
16
|
+
#
|
17
|
+
# This method will be called only when an Installer detection
|
18
|
+
# is run. It is ignored, when passing an Installer class
|
19
|
+
# directly as an config (`installer`) option.
|
20
|
+
#
|
21
|
+
# @param [Vagrant::VM]
|
22
|
+
# @return [Boolean]
|
23
|
+
def self.match?(vm)
|
24
|
+
false
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :vm
|
28
|
+
|
29
|
+
def initialize(vm, options=nil)
|
30
|
+
@vm = vm
|
31
|
+
@options = options
|
32
|
+
end
|
33
|
+
|
34
|
+
# The absolute file path of the GuestAdditions iso file should
|
35
|
+
# be uploaded into the guest.
|
36
|
+
# Subclasses must override this method!
|
37
|
+
#
|
38
|
+
# @return [String]
|
39
|
+
def tmp_path
|
40
|
+
end
|
41
|
+
|
42
|
+
# The mountpoint path
|
43
|
+
# Subclasses shall override this method, if they need to mount the uploaded file!
|
44
|
+
#
|
45
|
+
# @retunn [String]
|
46
|
+
def mount_point
|
47
|
+
end
|
48
|
+
|
49
|
+
# Handles the installation process.
|
50
|
+
# All necessary steps for an installation must be defined here.
|
51
|
+
# This includes uploading the iso into the box, mounting,
|
52
|
+
# installing and cleaning up.
|
53
|
+
# Subclasses must override this method!
|
54
|
+
#
|
55
|
+
# @param [String] iso_file Optional path to the local GuestAdditions iso file
|
56
|
+
# @param [Hash] opts Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends
|
57
|
+
# @yield [type, data] Takes a Block like {Vagrant::Communication::Base#execute} for realtime output of the command being executed
|
58
|
+
# @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc.
|
59
|
+
# @yieldparam [String] data Data for the given output.
|
60
|
+
def install(iso_fileO=nil, opts=nil, &block)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Handels the rebuild of allready installed GuestAdditions
|
64
|
+
# It may happen, that the guest has the correct GuestAdditions
|
65
|
+
# version installed, but not the kernel module is not loaded.
|
66
|
+
# This method should perform a rebuild or try to reload the
|
67
|
+
# kernel module _without_ the GuestAdditions iso file.
|
68
|
+
# If there is no way of rebuidling or reloading the
|
69
|
+
# GuestAdditions on a specific system, this method should left
|
70
|
+
# empty.
|
71
|
+
# Subclasses should override this method.
|
72
|
+
#
|
73
|
+
# @param [Hash] opts Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends
|
74
|
+
# @yield [type, data] Takes a Block like {Vagrant::Communication::Base#execute} for realtime output of the command being executed
|
75
|
+
# @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc.
|
76
|
+
# @yieldparam [String] data Data for the given output.
|
77
|
+
def rebuild(opts=nil, &block)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Determinates if the GuestAdditions kernel module is loaded.
|
81
|
+
# This method tests if there is a working GuestAdditions
|
82
|
+
# kernel module. If there is none, {#rebuild} is beeing called.
|
83
|
+
# If there is no way of telling if there is a working
|
84
|
+
# GuestAddition for a specific system, this method should
|
85
|
+
# return `true`.
|
86
|
+
# Subclasses should override this method.
|
87
|
+
#
|
88
|
+
# @return [Boolean] `true` if the kernel module is loaded (and thus seems to work), `false` otherwise.
|
89
|
+
def installed?(opts=nil, &block)
|
90
|
+
true
|
91
|
+
end
|
92
|
+
|
93
|
+
def needs_rebuild?(opts=nil, &block)
|
94
|
+
!installed?(opts, &block)
|
95
|
+
end
|
96
|
+
|
97
|
+
def need_reboot?(opts=nil, &block)
|
98
|
+
!installed?(opts, &block)
|
99
|
+
end
|
100
|
+
|
101
|
+
def iso_file
|
102
|
+
@iso_file ||= begin
|
103
|
+
iso_path = @options[:iso_path] || local_iso_path
|
104
|
+
|
105
|
+
if !iso_path || iso_path.empty? && !@options[:no_remote]
|
106
|
+
iso_path = VagrantVbguest::Helpers.web_iso_path_for @vm, @options
|
107
|
+
end
|
108
|
+
raise VagrantVbguest::IsoPathAutodetectionError if !iso_path || iso_path.empty?
|
109
|
+
|
110
|
+
iso_path.gsub! '$VBOX_VERSION', vm.driver.version
|
111
|
+
if Vagrant::Downloaders::File.match? iso_path
|
112
|
+
iso_path
|
113
|
+
else
|
114
|
+
# :TODO: This will also raise, if the iso_url points to an invalid local path
|
115
|
+
raise VagrantVbguest::DownloadingDisabledError.new(:from => iso_url) if @options[:no_remote]
|
116
|
+
env = {
|
117
|
+
:ui => vm.ui,
|
118
|
+
:tmp_path => vm.env.tmp_path,
|
119
|
+
:iso_url => iso_url
|
120
|
+
}
|
121
|
+
@download = VagrantVbguest::Download.new(@env)
|
122
|
+
@download.download
|
123
|
+
@download.temp_path
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def local_iso?
|
129
|
+
::File.file?(@env[:iso_url])
|
130
|
+
end
|
131
|
+
|
132
|
+
def local_iso_path
|
133
|
+
media_manager_iso || guess_iso
|
134
|
+
end
|
135
|
+
|
136
|
+
def web_iso_path
|
137
|
+
"http://download.virtualbox.org/virtualbox/$VBOX_VERSION/VBoxGuestAdditions_$VBOX_VERSION.iso"
|
138
|
+
end
|
139
|
+
|
140
|
+
def media_manager_iso
|
141
|
+
(m = vm.driver.execute('list', 'dvds').match(/^.+:\s+(.*VBoxGuestAdditions.iso)$/i)) && m[1]
|
142
|
+
end
|
143
|
+
|
144
|
+
def guess_iso
|
145
|
+
path_platform = if Vagrant::Util::Platform.linux?
|
146
|
+
"/usr/share/virtualbox/VBoxGuestAdditions.iso"
|
147
|
+
elsif Vagrant::Util::Platform.darwin?
|
148
|
+
"/Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso"
|
149
|
+
elsif Vagrant::Util::Platform.windows?
|
150
|
+
if (p = ENV["VBOX_INSTALL_PATH"]) && !p.empty?
|
151
|
+
File.join(p, "VBoxGuestAdditions.iso")
|
152
|
+
else
|
153
|
+
File.join((ENV["PROGRAM_FILES"] || ENV["ProgramW6432"] || ENV["PROGRAMFILES"]), "/Oracle/VirtualBox/VBoxGuestAdditions.iso")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
File.exists?(path_platform) ? path_platform : nil
|
157
|
+
end
|
158
|
+
|
159
|
+
# A helper method to handle the GuestAdditions iso file upload
|
160
|
+
def upload(file)
|
161
|
+
vm.ui.info(I18n.t("vagrant.plugins.vbguest.start_copy_iso", :from => file, :to => tmp_path))
|
162
|
+
vm.channel.upload(file, tmp_path)
|
163
|
+
end
|
164
|
+
|
165
|
+
# A helper method to delete the uploaded GuestAdditions iso file
|
166
|
+
# from the guest
|
167
|
+
def cleanup
|
168
|
+
@download.cleanup if @download
|
169
|
+
|
170
|
+
vm.channel.execute("rm #{tmp_path}", :error_check => false) do |type, data|
|
171
|
+
vm.ui.error(data.chomp, :prefix => false)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module VagrantVbguest
|
2
|
+
module Installers
|
3
|
+
class Debian < Linux
|
4
|
+
|
5
|
+
def self.match?(vm)
|
6
|
+
:debian == self.distro(vm)
|
7
|
+
end
|
8
|
+
|
9
|
+
# installes the correct linux-headers package
|
10
|
+
# installes `dkms` package for dynamic kernel module loading
|
11
|
+
def install(opts=nil, &block)
|
12
|
+
begin
|
13
|
+
vm.channel.sudo(install_dependencies_cmd, opts, &block)
|
14
|
+
rescue
|
15
|
+
vm.channel.sudo('apt-get update', opts, &block)
|
16
|
+
vm.channel.sudo(install_dependencies_cmd, opts, &block)
|
17
|
+
end
|
18
|
+
upload(iso_file)
|
19
|
+
vm.channel.sudo("mount #{tmp_path} -o loop #{mount_point}", opts, &block)
|
20
|
+
vm.channel.sudo("#{mount_point}/VBoxLinuxAdditions.run --nox11", opts, &block)
|
21
|
+
vm.channel.sudo("umount #{mount_point}", opts, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
def install_dependencies_cmd
|
26
|
+
"apt-get install -y #{dependencies}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def dependencies
|
30
|
+
packages = ['linux-headers-`uname -r`']
|
31
|
+
# some Debian system (lenny) dont come with a dkms packe so we neet to skip that.
|
32
|
+
# apt-cache search will exit with 0 even if nothing was found, so we need to grep.
|
33
|
+
packages << 'dkmx' if vm.channel.test('apt-cache search --names-only \'^dkms$\' | grep dkms')
|
34
|
+
packages.join ' '
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
VagrantVbguest::Installer.register(VagrantVbguest::Installers::Debian, 5)
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module VagrantVbguest
|
2
|
+
module Installers
|
3
|
+
# A basic Installer implementation for vanilla or
|
4
|
+
# unknown Linux based systems.
|
5
|
+
class Linux < Base
|
6
|
+
|
7
|
+
# A helper method to cache the result of {Vagrant::Guest::Base#distro_dispatch}
|
8
|
+
# which speeds up Installer detection runs a lot,
|
9
|
+
# when having lots of Linux based Installer classes
|
10
|
+
# to check.
|
11
|
+
#
|
12
|
+
# @see {Vagrant::Guest::Linux#distro_dispatch}
|
13
|
+
# @return [Symbol] One of `:debian`, `:ubuntu`, `:gentoo`, `:fedora`, `:redhat`, `:suse`, `:arch`
|
14
|
+
def self.distro(vm)
|
15
|
+
@@ditro ||= {}
|
16
|
+
@@ditro[vm.uuid] ||= vm.guest.distro_dispatch
|
17
|
+
end
|
18
|
+
|
19
|
+
# Matches if the operating system name prints "Linux"
|
20
|
+
# Raises an Error if this class is beeing subclassed but
|
21
|
+
# this method was not overridden. This is considered an
|
22
|
+
# error because, subclassed Installers usually indicate
|
23
|
+
# a more specific distributen like 'ubuntu' or 'arch' and
|
24
|
+
# therefore should do a more specific check.
|
25
|
+
def self.match?(vm)
|
26
|
+
raise Error, :_key => :do_not_inherit_match_method if self.class != Linux
|
27
|
+
vm.channel.test("uname | grep 'Linux'")
|
28
|
+
end
|
29
|
+
|
30
|
+
# defaults the temp path to "/tmp/VBoxGuestAdditions.iso" for all Linux based systems
|
31
|
+
def tmp_path
|
32
|
+
'/tmp/VBoxGuestAdditions.iso'
|
33
|
+
end
|
34
|
+
|
35
|
+
# defaults the mount point to "/mnt" for all Linux based systems
|
36
|
+
def mount_point
|
37
|
+
'/mnt'
|
38
|
+
end
|
39
|
+
|
40
|
+
# a generic way of installing GuestAdditions assuming all
|
41
|
+
# dependencies on the guest are installed
|
42
|
+
def install(iso_file = nil, opts=nil, &block)
|
43
|
+
vm.ui.warn I18n.t("vagrant.plugins.vbguest.installer.generic_linux_installer")
|
44
|
+
upload(iso_file)
|
45
|
+
vm.channel.sudo("mount #{tmp_path} -o loop #{mount_point}", opts, &block)
|
46
|
+
vm.channel.sudo("#{mount_point}/VBoxLinuxAdditions.run --nox11", opts, &block)
|
47
|
+
vm.channel.sudo("umount #{mount_point}", opts, &block)
|
48
|
+
end
|
49
|
+
|
50
|
+
def installed?(opts=nil, &block)
|
51
|
+
opts = {
|
52
|
+
:sudo => true
|
53
|
+
}.merge(opts || {})
|
54
|
+
vm.channel.test('lsmod | grep vboxsf', opts, &block)
|
55
|
+
end
|
56
|
+
|
57
|
+
def rebuild(opts=nil, &block)
|
58
|
+
vm.channel.sudo('/etc/init.d/vboxadd setup', opts, &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
VagrantVbguest::Installer.register(VagrantVbguest::Installers::Linux, 2)
|
@@ -15,13 +15,14 @@ module VagrantVbguest
|
|
15
15
|
|
16
16
|
def call(env)
|
17
17
|
options = @vm.config.vbguest.to_hash
|
18
|
-
VagrantVbguest::Installer.new(@vm, options)
|
18
|
+
installer = VagrantVbguest::Installer.new(@vm, options)
|
19
|
+
installer.run
|
19
20
|
|
20
|
-
if need_reboot?
|
21
|
+
if installer.need_reboot?
|
21
22
|
if rebooted?(@vm)
|
22
23
|
@vm.ui.error(I18n.t("vagrant.plugins.vbguest.restart_loop_guard_activated"))
|
23
24
|
else
|
24
|
-
reboot(@vm, options)
|
25
|
+
reboot(@vm, options)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
data/locales/en.yml
CHANGED
@@ -11,8 +11,6 @@ en:
|
|
11
11
|
restart_vm: "Restarting VM to apply changes..."
|
12
12
|
suggest_restart: "Guest Additions got installed. However, they seem not be loaded correctly. Please restart the box runing `vagrant reload %{name}`"
|
13
13
|
restart_loop_guard_activated: "Guest Additions will not load, even after reboot."
|
14
|
-
no_install_script_for_platform: "Sorry, don't know how to install on a %{platform} system. Stopping installation."
|
15
|
-
generic_install_script_for_platform: "%{platform} is currently not supported, will try generic Linux method..."
|
16
14
|
guest_version_reports_differ: |-
|
17
15
|
Got different reports about installed GuestAdditions version:
|
18
16
|
Virtualbox on your host claims: %{driver}
|
@@ -34,6 +32,14 @@ en:
|
|
34
32
|
Please configure a local path to the iso using `config.vbguest.iso_path`
|
35
33
|
in your Vagrantfile or the `--iso` command line option.
|
36
34
|
|
35
|
+
installer:
|
36
|
+
no_installer_for_platform: |-
|
37
|
+
Sorry, don't know how to %{method} Virtualbox Guest Additions on this platform. Stopping installation.
|
38
|
+
generic_linux_installer: |-
|
39
|
+
The guest's platform is currently not supported, will try generic Linux method...
|
40
|
+
do_not_inherit_match_method: |-
|
41
|
+
Installer classes must proviode their own `match?` method.
|
42
|
+
|
37
43
|
download:
|
38
44
|
with: "Downloading VirtualBox Guest Additions ISO with %{class}..."
|
39
45
|
cleaning: "Cleaning up downloaded VirtualBox Guest Additions ISO..."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-vbguest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.0.
|
4
|
+
version: 0.6.0.pre1
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -50,6 +50,10 @@ files:
|
|
50
50
|
- lib/vagrant-vbguest/errors.rb
|
51
51
|
- lib/vagrant-vbguest/helpers.rb
|
52
52
|
- lib/vagrant-vbguest/installer.rb
|
53
|
+
- lib/vagrant-vbguest/installers/base.rb
|
54
|
+
- lib/vagrant-vbguest/installers/debian.rb
|
55
|
+
- lib/vagrant-vbguest/installers/linux.rb
|
56
|
+
- lib/vagrant-vbguest/installers/ubuntu.rb
|
53
57
|
- lib/vagrant-vbguest/middleware.rb
|
54
58
|
- lib/vagrant-vbguest/version.rb
|
55
59
|
- lib/vagrant_init.rb
|