module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
end
def OS.unix?
!OS.windows?
end
def OS.linux?
OS.unix? and not OS.mac?
end
end
ENV['VAGRANT_DEFAULT_PROVIDER'] ||= OS.mac? ? 'vmware_appcatalyst' : "vmware_workstation"
fusion_path="/Applications/VMware Fusion.app/Contents/Library"
if File.directory?(fusion_path)
ENV['PATH'] = "#{fusion_path}:#{ENV['PATH']}"
end
appcatalyst_path="/opt/vmware/appcatalyst/libexec"
if File.directory?(appcatalyst_path)
ENV['PATH'] = "#{appcatalyst_path}:#{ENV['PATH']}"
end
# Hey Now! thanks StackOverflow: http://stackoverflow.com/a/28801317/1233435
req_plugins = %w(vagrant-triggers
vagrant-guestip
vagrant-guests-photon)
if OS.mac?
req_plugins << "vagrant-vmware-fusion" if File.directory?(fusion_path)
req_plugins << "vagrant-vmware-appcatalyst" if File.directory?(appcatalyst_path)
else
req_plugins << "vagrant-vmware-workstation"
end
# Cycle through the required plugins and install what's missing.
plugins_install = req_plugins.select { |plugin| !Vagrant.has_plugin? plugin }
licensed_plugins = plugins_install.select { |plugin| plugin =~ /vagrant-vmware-(?:fusion|workstation)$/ }
licensed_plugins.each do |plugin|
unless File.exist? "#{ENV["VAGRANT_VMWARE_LICENSE_FILE"]||"./#{plugin}.lic"}"
abort "Failed to configure license, you can configure the path with VAGRANT_VMWARE_LICENSE_FILE"
end
end
unless plugins_install.empty?
puts "Installing plugins: #{plugins_install.join(' ')}"
if system "vagrant plugin install #{plugins_install.join(' ')}"
exec "vagrant #{ARGV.join(' ')}"
else
abort 'Installation of one or more plugins has failed. Aborting.'
end
end
licensed_plugins.each do |plugin|
unless system "vagrant plugin license #{plugin} #{ENV["VAGRANT_VMWARE_LICENSE_FILE"]||"./#{plugin}.lic"}"
abort "Failed to configure license, you can configure the path with VAGRANT_VMWARE_LICENSE_FILE"
end
end