Class: VagrantVbguest::Installers::Linux
- Defined in:
- lib/vagrant-vbguest/installers/linux.rb
Overview
A basic Installer implementation for vanilla or unknown Linux based systems.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.distro(vm) ⇒ Symbol
A helper method to cache the result of Vagrant::Guest::Base#distro_dispatch which speeds up Installer detection runs a lot, when having lots of Linux based Installer classes to check.
-
.match?(vm) ⇒ Boolean
Matches if the operating system name prints “Linux” Raises an Error if this class is beeing subclassed but this method was not overridden.
Instance Method Summary collapse
-
#execute_installer(opts = nil) {|type, data| ... } ⇒ Object
A generic helper method to execute the installer.
-
#guest_version(reload = false) ⇒ String
This overrides Base#guest_version to also query the ‘VBoxService` on the host system (if available) for it’s version.
-
#install(opts = nil) {|type, data| ... } ⇒ Object
a generic way of installing GuestAdditions assuming all dependencies on the guest are installed.
-
#installer ⇒ Object
The absolute path to the GuestAdditions installer script.
-
#installer_arguments ⇒ Object
The arguments string, which gets passed to the installer script.
-
#mount_iso(opts = nil) {|type, data| ... } ⇒ Object
A generic helper method for mounting the GuestAdditions iso file on most linux system.
-
#mount_point ⇒ Object
defaults the mount point to “/mnt” for all Linux based systems.
- #rebuild(opts = nil) {|type, data| ... } ⇒ Object
- #running?(opts = nil) {|type, data| ... } ⇒ Boolean
- #start(opts = nil) {|type, data| ... } ⇒ Object
-
#tmp_path ⇒ Object
defaults the temp path to “/tmp/VBoxGuestAdditions.iso” for all Linux based systems.
-
#unmount_iso(opts = nil) {|type, data| ... } ⇒ Object
A generic helper method for un-mounting the GuestAdditions iso file on most linux system Unmounts the
mount_point
.
Methods inherited from Base
#cleanup, #initialize, #installer_version, #iso_file, #upload, #yield_installation_error_warning, #yield_installation_waring, #yield_rebuild_warning
Methods included from Helpers::VmCompatible
#communicate, #driver, included
Constructor Details
This class inherits a constructor from VagrantVbguest::Installers::Base
Class Method Details
.distro(vm) ⇒ Symbol
A helper method to cache the result of Vagrant::Guest::Base#distro_dispatch which speeds up Installer detection runs a lot, when having lots of Linux based Installer classes to check.
14 15 16 17 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 14 def self.distro(vm) @@ditro ||= {} @@ditro[ vm_id(vm) ] ||= distro_name vm end |
.match?(vm) ⇒ Boolean
Matches if the operating system name prints “Linux” Raises an Error if this class is beeing subclassed but this method was not overridden. This is considered an error because, subclassed Installers usually indicate a more specific distributen like ‘ubuntu’ or ‘arch’ and therefore should do a more specific check.
25 26 27 28 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 25 def self.match?(vm) raise Error, :_key => :do_not_inherit_match_method if self != Linux communicate_to(vm).test("uname | grep 'Linux'") end |
Instance Method Details
#execute_installer(opts = nil) {|type, data| ... } ⇒ Object
A generic helper method to execute the installer. This also yields a installation warning to the user, and an error warning in the event that the installer returns a non-zero exit status.
113 114 115 116 117 118 119 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 113 def execute_installer(opts=nil, &block) yield_installation_waring(installer) opts = {:error_check => false}.merge(opts || {}) exit_status = communicate.sudo("#{installer} #{installer_arguments}", opts, &block) yield_installation_error_warning(installer) unless exit_status == 0 exit_status end |
#guest_version(reload = false) ⇒ String
This overrides Base#guest_version to also query the ‘VBoxService` on the host system (if available) for it’s version. In some scenarios the results of the VirtualBox driver and the additions installed on the host may differ. If this happens, we assume, that the host binaries are right and yield a warning message.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 74 def guest_version(reload = false) return @guest_version if @guest_version && !reload driver_version = super communicate.sudo('VBoxService --version', :error_check => false) do |type, data| if (v = data.to_s.match(/^(\d+\.\d+.\d+)/)) && driver_version != v[1] @env.ui.warn(I18n.t("vagrant_vbguest.guest_version_reports_differ", :driver => driver_version, :service => v[1])) @guest_version = v[1] end end @guest_version end |
#install(opts = nil) {|type, data| ... } ⇒ Object
a generic way of installing GuestAdditions assuming all dependencies on the guest are installed
46 47 48 49 50 51 52 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 46 def install(opts=nil, &block) env.ui.warn I18n.t("vagrant_vbguest.errors.installer.generic_linux_installer") if self.class == Linux upload(iso_file) mount_iso(opts, &block) execute_installer(opts, &block) unmount_iso(opts, &block) end |
#installer ⇒ Object
The absolute path to the GuestAdditions installer script. The iso file has to be mounted on mount_point
.
123 124 125 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 123 def installer @installer ||= File.join(mount_point, 'VBoxLinuxAdditions.run') end |
#installer_arguments ⇒ Object
The arguments string, which gets passed to the installer script
128 129 130 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 128 def installer_arguments @installer_arguments ||= Array([:installer_arguments]).join " " end |
#mount_iso(opts = nil) {|type, data| ... } ⇒ Object
A generic helper method for mounting the GuestAdditions iso file on most linux system. Mounts the given uploaded file from tmp_path
on mount_point
.
140 141 142 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 140 def mount_iso(opts=nil, &block) communicate.sudo("mount #{tmp_path} -o loop #{mount_point}", opts, &block) end |
#mount_point ⇒ Object
defaults the mount point to “/mnt” for all Linux based systems
36 37 38 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 36 def mount_point '/mnt' end |
#rebuild(opts = nil) {|type, data| ... } ⇒ Object
91 92 93 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 91 def rebuild(opts=nil, &block) communicate.sudo('/etc/init.d/vboxadd setup', opts, &block) end |
#running?(opts = nil) {|type, data| ... } ⇒ Boolean
58 59 60 61 62 63 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 58 def running?(opts=nil, &block) opts = { :sudo => true }.merge(opts || {}) communicate.test('lsmod | grep vboxsf', opts, &block) end |
#start(opts = nil) {|type, data| ... } ⇒ Object
99 100 101 102 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 99 def start(opts=nil, &block) opts = {:error_check => false}.merge(opts || {}) communicate.sudo('/etc/init.d/vboxadd start', opts, &block) end |
#tmp_path ⇒ Object
defaults the temp path to “/tmp/VBoxGuestAdditions.iso” for all Linux based systems
31 32 33 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 31 def tmp_path '/tmp/VBoxGuestAdditions.iso' end |
#unmount_iso(opts = nil) {|type, data| ... } ⇒ Object
A generic helper method for un-mounting the GuestAdditions iso file on most linux system Unmounts the mount_point
.
152 153 154 |
# File 'lib/vagrant-vbguest/installers/linux.rb', line 152 def unmount_iso(opts=nil, &block) communicate.sudo("umount #{mount_point}", opts, &block) end |