lib/vagrant-vbguest/installers/linux.rb in vagrant-vbguest-0.10.1 vs lib/vagrant-vbguest/installers/linux.rb in vagrant-vbguest-0.11.0.beta0

- old
+ new

@@ -25,35 +25,41 @@ def self.match?(vm) raise Error, :_key => :do_not_inherit_match_method if self != Linux communicate_to(vm).test("uname | grep 'Linux'") end - # defaults the temp path to "/tmp/VBoxGuestAdditions.iso" for all Linux based systems + # The temporary path where to upload the iso file to. + # Configurable via `config.vbguest.iso_upload_path`. + # Defaults the temp path to `/tmp/VBoxGuestAdditions.iso" for + # all Linux based systems def tmp_path - '/tmp/VBoxGuestAdditions.iso' + options[:iso_upload_path] || '/tmp/VBoxGuestAdditions.iso' end - # defaults the mount point to "/mnt" for all Linux based systems + # Mount point for the iso file. + # Configurable via `config.vbguest.iso_mount_point`. + #Ddefaults to "/mnt" for all Linux based systems. def mount_point - '/mnt' + options[:iso_mount_point] || '/mnt' end # a generic way of installing GuestAdditions assuming all # dependencies on the guest are installed - # @param [Hash] opts Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends + # + # @param opts [Hash] Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends # @yield [type, data] Takes a Block like {Vagrant::Communication::Base#execute} for realtime output of the command being executed # @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc. # @yieldparam [String] data Data for the given output. def install(opts=nil, &block) - env.ui.warn I18n.t("vagrant_vbguest.errors.installer.generic_linux_installer") if self.class == Linux + env.ui.warn I18n.t("vagrant_vbguest.errors.installer.generic_linux_installer", distro: self.class.distro(vm)) if self.class == Linux upload(iso_file) mount_iso(opts, &block) execute_installer(opts, &block) - unmount_iso(opts, &block) + unmount_iso(opts, &block) unless options[:no_cleanup] end - # @param [Hash] opts Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends + # @param opts [Hash] Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends # @yield [type, data] Takes a Block like {Vagrant::Communication::Base#execute} for realtime output of the command being executed # @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc. # @yieldparam [String] data Data for the given output. def running?(opts=nil, &block) opts = { @@ -82,33 +88,91 @@ end end @guest_version end - # @param [Hash] opts Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends + # @param opts [Hash] Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends # @yield [type, data] Takes a Block like {Vagrant::Communication::Base#execute} for realtime output of the command being executed # @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc. # @yieldparam [String] data Data for the given output. def rebuild(opts=nil, &block) - communicate.sudo('/etc/init.d/vboxadd setup', opts, &block) + communicate.sudo("#{vboxadd_tool} setup", opts, &block) end - # @param [Hash] opts Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends + # @param opts [Hash] Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends # @yield [type, data] Takes a Block like {Vagrant::Communication::Base#execute} for realtime output of the command being executed # @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc. # @yieldparam [String] data Data for the given output. def start(opts=nil, &block) opts = {:error_check => false}.merge(opts || {}) - communicate.sudo('/etc/init.d/vboxadd start', opts, &block) + systemd = systemd_tool + if systemd + communicate.sudo("#{systemd[:path]} vboxadd #{systemd[:up]}", opts, &block) + else + communicate.sudo("#{vboxadd_tool} start", opts, &block) + end end + # Check for the presence of 'systemd' chkconfg or service command. + # + # systemd_tool # => {:path=>"/usr/sbin/service", :up=>"start"} + # + # @return [Hash|nil] Hash with an absolute +path+ to the tool and the + # command string for starting. + # +nil* if neither was found. + def systemd_tool + result = nil + communicate.sudo('(which chkconfg || which service) 2>/dev/null', {:error_check => false}) do |type, data| + path = data.to_s + case path + when /\bservice\b/ + result = { path: path, up: "start" } + when /\chkconfg\b/ + result = { path: path, up: "on" } + end + end + result + end + # Checks for the correct location of the 'vboxadd' tool. + # It checks for a given list of possible locations. This list got + # extracted from the 'VBoxLinuxAdditions.run' script. + # + # @return [String|nil] Absolute path to the +vboxadd+ tool, + # or +nil+ if none found. + def vboxadd_tool + candidates = [ + "/usr/lib/i386-linux-gnu/VBoxGuestAdditions/vboxadd", + "/usr/lib/x86_64-linux-gnu/VBoxGuestAdditions/vboxadd", + "/usr/lib64/VBoxGuestAdditions/vboxadd", + "/usr/lib/VBoxGuestAdditions/vboxadd", + "/lib64/VBoxGuestAdditions/vboxadd", + "/lib/VBoxGuestAdditions/vboxadd", + "/etc/init.d/vboxadd", + ] + bin_path = "" + cmd = <<-SHELL + for c in #{candidates.join(" ")}; do + if test -x "$c"; then + echo $c + break + fi + done + SHELL + + path = nil + communicate.sudo(cmd, {:error_check => false}) do |type, data| + path = data.strip unless data.empty? + end + path + end + # 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. # - # @param [Hash] opts Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends + # @param opts [Hash] Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends # @yield [type, data] Takes a Block like {Vagrant::Communication::Base#execute} for realtime output of the command being executed # @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc. # @yieldparam [String] data Data for the given output. def execute_installer(opts=nil, &block) yield_installation_waring(installer) @@ -131,11 +195,11 @@ # 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+. # - # @param [Hash] opts Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends + # @param opts [Hash] Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends # @yield [type, data] Takes a Block like {Vagrant::Communication::Base#execute} for realtime output of the command being executed # @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc. # @yieldparam [String] data Data for the given output. def mount_iso(opts=nil, &block) communicate.sudo("mount #{tmp_path} -o loop #{mount_point}", opts, &block) @@ -143,10 +207,10 @@ # A generic helper method for un-mounting the GuestAdditions iso file # on most linux system # Unmounts the +mount_point+. # - # @param [Hash] opts Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends + # @param opts [Hash] Optional options Hash wich meight get passed to {Vagrant::Communication::SSH#execute} and firends # @yield [type, data] Takes a Block like {Vagrant::Communication::Base#execute} for realtime output of the command being executed # @yieldparam [String] type Type of the output, `:stdout`, `:stderr`, etc. # @yieldparam [String] data Data for the given output. def unmount_iso(opts=nil, &block) communicate.sudo("umount #{mount_point}", opts, &block)