From d6028835cb0200d75e3c606a13e0858b0dba2743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Tue, 26 May 2020 11:50:56 +0300 Subject: [PATCH] WIP: Automatically check and abort if VirtualBox version not compatible Related: #96, #122 --- Vagrantfile | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 6e4ce82..30d2455 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -125,7 +125,6 @@ Vagrant.configure('2') do |config| # We have tried using NFS but it's super slow compared to synced_folder config.vm.synced_folder DIR, '/data/wordpress/', owner: 'vagrant', group: 'vagrant', mount_options: ['dmode=775', 'fmode=775'] - # For Self-signed ssl-certificate ssl_cert_path = File.join(DIR,'.vagrant','ssl') unless File.exists? File.join(ssl_cert_path,'development.crt') @@ -145,6 +144,7 @@ Vagrant.configure('2') do |config| end config.vm.provider 'virtualbox' do |vb| + # Give VM access to all cpu cores on the host cpus = case RbConfig::CONFIG['host_os'] when /darwin/ then `sysctl -n hw.physicalcpu`.to_i @@ -162,6 +162,10 @@ Vagrant.configure('2') do |config| vb.customize ['modifyvm', :id, '--uartmode1', 'disconnected'] end + virtualbox_version_check + puts "end" + exit 1 + end ## @@ -483,6 +487,28 @@ def vagrant_running? system("vagrant status --machine-readable | grep state,running --quiet") end +def virtualbox_version_check + min_ver = "5.2" + max_ver = "6.1" + + vboxmanage = Vagrant::Util::Which.which("VBoxManage") || Vagrant::Util::Which.which("VBoxManage.exe") + if vboxmanage != nil + s = Vagrant::Util::Subprocess.execute(vboxmanage, '--version') + ver = s.stdout.strip![0..2] + puts "Found VirtualBox version #{ver}" + else + STDERR.puts "VirtualBox not installed, aborting.." + exit 1 + end + + if ver <= min_ver + STDERR.puts "VirtualBox version #{ver} is too low. Requires at least #{min_ver}." + elsif ver > max_ver + STDERR.puts "VirtualBox version #{ver} is too high. Please downgrade to #{max_ver}." + end + exit 1 +end + ## # On OS X we can use a few more features like zeroconf (discovery of .local addresses in local network) ##