vagrant/plugins/hosts/windows/cap/provider_install_virtualbox.rb

53 lines
1.7 KiB
Ruby
Raw Normal View History

2015-11-05 03:37:55 +00:00
require "pathname"
require "tempfile"
require "vagrant/util/downloader"
require "vagrant/util/powershell"
2015-11-05 03:37:55 +00:00
require "vagrant/util/subprocess"
module VagrantPlugins
module HostWindows
module Cap
class ProviderInstallVirtualBox
# The URL to download VirtualBox is hardcoded so we can have a
# known-good version to download.
2015-11-24 06:54:31 +00:00
URL = "http://download.virtualbox.org/virtualbox/5.0.10/VirtualBox-5.0.10-104061-Win.exe".freeze
VERSION = "5.0.10".freeze
2015-11-05 03:37:55 +00:00
def self.provider_install_virtualbox(env)
tf = Tempfile.new("vagrant")
tf.close
# Prefixed UI for prettiness
ui = Vagrant::UI::Prefixed.new(env.ui, "")
# Start by downloading the file using the standard mechanism
ui.output(I18n.t(
"vagrant.hosts.windows.virtualbox_install_download",
version: VERSION))
ui.detail(I18n.t(
"vagrant.hosts.windows.virtualbox_install_detail"))
dl = Vagrant::Util::Downloader.new(URL, tf.path, ui: ui)
dl.download!
# Launch it
ui.output(I18n.t(
"vagrant.hosts.windows.virtualbox_install_install"))
ui.detail(I18n.t(
"vagrant.hosts.windows.virtualbox_install_install_detail"))
script = File.expand_path("../../scripts/install_virtualbox.ps1", __FILE__)
result = Vagrant::Util::PowerShell.execute(script, tf.path)
2015-11-05 03:37:55 +00:00
if result.exit_code != 0
raise Vagrant::Errors::ProviderInstallFailed,
provider: "virtualbox",
stdout: result.stdout,
stderr: result.stderr
end
ui.success(I18n.t("vagrant.hosts.windows.virtualbox_install_success"))
end
end
end
end
end