hosts/darwin: support virtualbox install

This commit is contained in:
Mitchell Hashimoto 2015-11-04 15:47:56 -08:00
parent 72e13ee9ef
commit dad5962ebb
7 changed files with 104 additions and 3 deletions

View File

@ -524,6 +524,10 @@ module Vagrant
error_key(:provider_cant_install)
end
class ProviderInstallFailed < VagrantError
error_key(:provider_install_failed)
end
class ProviderNotFound < VagrantError
error_key(:provider_not_found)
end

View File

@ -319,6 +319,7 @@ module Vagrant
target = @prefix
target = opts[:target] if opts.key?(:target)
target = "#{target}:" if target != ""
# Get the lines. The first default is because if the message
# is an empty string, then we want to still use the empty string.
@ -327,7 +328,7 @@ module Vagrant
# Otherwise, make sure to prefix every line properly
lines.map do |line|
"#{prefix}#{target}: #{line}"
"#{prefix}#{target} #{line}"
end.join("\n")
end
end

View File

@ -53,12 +53,13 @@ module VagrantPlugins
# Check if we're requesting installation
if options[:install]
if !machine.provider.capability?(:install)
key = "provider_install_#{machine.provider_name}".to_sym
if !@env.host.capability?(key)
raise Vagrant::Errors::ProviderCantInstall,
provider: machine.provider_name.to_s
end
machine.provider.capability(:install)
@env.host.capability(key)
return
end

View File

@ -0,0 +1,51 @@
require "pathname"
require "tempfile"
require "vagrant/util/downloader"
require "vagrant/util/subprocess"
module VagrantPlugins
module HostDarwin
module Cap
class ProviderInstallVirtualBox
# The URL to download VirtualBox is hardcoded so we can have a
# known-good version to download.
URL = "http://download.virtualbox.org/virtualbox/5.0.8/VirtualBox-5.0.8-103449-OSX.dmg".freeze
VERSION = "5.0.8".freeze
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.darwin.virtualbox_install_download",
version: VERSION))
ui.detail(I18n.t(
"vagrant.hosts.darwin.virtualbox_install_detail"))
dl = Vagrant::Util::Downloader.new(URL, tf.path, ui: ui)
dl.download!
# Launch it
ui.output(I18n.t(
"vagrant.hosts.darwin.virtualbox_install_install"))
ui.detail(I18n.t(
"vagrant.hosts.darwin.virtualbox_install_install_detail"))
script = File.expand_path("../../scripts/install_virtualbox.sh", __FILE__)
result = Vagrant::Util::Subprocess.execute("bash", script, tf.path)
if result.exit_code != 0
raise Vagrant::Errors::ProviderInstallFailed,
provider: "virtualbox",
stdout: result.stdout,
stderr: result.stderr
end
ui.success(I18n.t("vagrant.hosts.darwin.virtualbox_install_success"))
end
end
end
end
end

View File

@ -11,6 +11,11 @@ module VagrantPlugins
Host
end
host_capability("darwin", "provider_install_virtualbox") do
require_relative "cap/provider_install_virtualbox"
Cap::ProviderInstallVirtualBox
end
host_capability("darwin", "rdp_client") do
require_relative "cap/rdp"
Cap::RDP

View File

@ -0,0 +1,15 @@
#!/bin/bash
set -e
hdiutil attach $1
cd /Volumes/VirtualBox/
sudo installer -pkg VirtualBox.pkg -target "/"
cd /tmp
flag=1
while [ $flag -ne 0 ]; do
sleep 1
set +e
hdiutil detach /Volumes/VirtualBox/
flag=$?
set -e
done

View File

@ -280,6 +280,7 @@ en:
CHANGELOG below:
https://github.com/mitchellh/vagrant/blob/v%{version}/CHANGELOG.md
cfengine_config:
classes_array: |-
The 'classes' configuration must be an array.
@ -1006,6 +1007,14 @@ en:
This is a limitation of this provider. Please report this as a feature
request to the provider in question. To install this provider, you'll
have to do so manually.
provider_install_failed: |-
Installation of the provider '%{provider}' failed! The stdout
and stderr are shown below. Please read the error output, resolve it,
and try again. If problem persists, please install the provider
manually.
Stdout: %{stdout}
Stderr: %{stderr}
provider_not_found: |-
The provider '%{provider}' could not be found, but was requested to
back the machine '%{machine}'. Please use a provider that exists.
@ -1867,6 +1876,21 @@ en:
Preparing to edit /etc/exports. Administrator privileges will be required...
nfs_prune: |-
Pruning invalid NFS exports. Administrator privileges will be required...
darwin:
virtualbox_install_download: |-
Downloading VirtualBox %{version}...
virtualbox_install_detail: |-
This may not be the latest version of VirtualBox, but it is a version
that is known to work well. Over time, we'll update the version that
is installed.
virtualbox_install_install: |-
Installing VirtualBox. This will take a few minutes...
virtualbox_install_install_detail: |-
You may be asked for your administrator password during this time.
If you're uncomfortable entering your password here, please install
VirtualBox manually.
virtualbox_install_success: |-
VirtualBox has successfully been installed!
linux:
nfs_export: |-
Preparing to edit /etc/exports. Administrator privileges will be required...