providers/virtualbox: more robust lookup for VBoxManage on Win
This commit is contained in:
parent
c471f37955
commit
3c2fab9d0d
|
@ -2,6 +2,7 @@ require "pathname"
|
||||||
require "tempfile"
|
require "tempfile"
|
||||||
|
|
||||||
require "vagrant/util/downloader"
|
require "vagrant/util/downloader"
|
||||||
|
require "vagrant/util/powershell"
|
||||||
require "vagrant/util/subprocess"
|
require "vagrant/util/subprocess"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
|
@ -35,7 +36,7 @@ module VagrantPlugins
|
||||||
ui.detail(I18n.t(
|
ui.detail(I18n.t(
|
||||||
"vagrant.hosts.windows.virtualbox_install_install_detail"))
|
"vagrant.hosts.windows.virtualbox_install_install_detail"))
|
||||||
script = File.expand_path("../../scripts/install_virtualbox.ps1", __FILE__)
|
script = File.expand_path("../../scripts/install_virtualbox.ps1", __FILE__)
|
||||||
result = Vagrant::Util::Powershell.execute(script, tf.path)
|
result = Vagrant::Util::PowerShell.execute(script, tf.path)
|
||||||
if result.exit_code != 0
|
if result.exit_code != 0
|
||||||
raise Vagrant::Errors::ProviderInstallFailed,
|
raise Vagrant::Errors::ProviderInstallFailed,
|
||||||
provider: "virtualbox",
|
provider: "virtualbox",
|
||||||
|
|
|
@ -4,6 +4,7 @@ require 'vagrant/util/busy'
|
||||||
require 'vagrant/util/platform'
|
require 'vagrant/util/platform'
|
||||||
require 'vagrant/util/retryable'
|
require 'vagrant/util/retryable'
|
||||||
require 'vagrant/util/subprocess'
|
require 'vagrant/util/subprocess'
|
||||||
|
require 'vagrant/util/which'
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module ProviderVirtualBox
|
module ProviderVirtualBox
|
||||||
|
@ -22,16 +23,16 @@ module VagrantPlugins
|
||||||
# This flag is used to keep track of interrupted state (SIGINT)
|
# This flag is used to keep track of interrupted state (SIGINT)
|
||||||
@interrupted = false
|
@interrupted = false
|
||||||
|
|
||||||
# Set the path to VBoxManage
|
|
||||||
@vboxmanage_path = "VBoxManage"
|
|
||||||
|
|
||||||
if Vagrant::Util::Platform.windows? || Vagrant::Util::Platform.cygwin?
|
if Vagrant::Util::Platform.windows? || Vagrant::Util::Platform.cygwin?
|
||||||
@logger.debug("Windows. Trying VBOX_INSTALL_PATH for VBoxManage")
|
@logger.debug("Windows, checking for VBoxManage on PATH first")
|
||||||
|
@vboxmanage_path = Vagrant::Util::Which.which("VBoxManage")
|
||||||
|
|
||||||
# On Windows, we use the VBOX_INSTALL_PATH environmental
|
# On Windows, we use the VBOX_INSTALL_PATH environmental
|
||||||
# variable to find VBoxManage.
|
# variable to find VBoxManage.
|
||||||
if ENV.key?("VBOX_INSTALL_PATH") ||
|
if !@vboxmanage_path && (ENV.key?("VBOX_INSTALL_PATH") ||
|
||||||
ENV.key?("VBOX_MSI_INSTALL_PATH")
|
ENV.key?("VBOX_MSI_INSTALL_PATH"))
|
||||||
|
@logger.debug("Windows. Trying VBOX_INSTALL_PATH for VBoxManage")
|
||||||
|
|
||||||
# Get the path.
|
# Get the path.
|
||||||
path = ENV["VBOX_INSTALL_PATH"] || ENV["VBOX_MSI_INSTALL_PATH"]
|
path = ENV["VBOX_INSTALL_PATH"] || ENV["VBOX_MSI_INSTALL_PATH"]
|
||||||
@logger.debug("VBOX_INSTALL_PATH value: #{path}")
|
@logger.debug("VBOX_INSTALL_PATH value: #{path}")
|
||||||
|
@ -51,8 +52,24 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If we still don't have one, try to find it using common locations
|
||||||
|
drive = ENV["SYSTEMDRIVE"] || "C:"
|
||||||
|
[
|
||||||
|
"#{drive}/Program Files/Oracle/VirtualBox",
|
||||||
|
"#{drive}/Program Files (x86)/Oracle/VirtualBox",
|
||||||
|
"#{ENV["PROGRAMFILES"]}/Oracle/VirtualBox"
|
||||||
|
].each do |maybe|
|
||||||
|
path = File.join(maybe, "VBoxManage.exe")
|
||||||
|
if File.file?(path)
|
||||||
|
@vboxmanage_path = path
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Fall back to hoping for the PATH to work out
|
||||||
|
@vboxmanage_path ||= "VBoxManage"
|
||||||
@logger.info("VBoxManage path: #{@vboxmanage_path}")
|
@logger.info("VBoxManage path: #{@vboxmanage_path}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue