# -*- mode: ruby -*-
# vi: set ft=ruby :

# rubocop:disable LineLength

# plugins don't seem to be auto-loaded from the bundle
require "vagrant-omnibus"

def box_type
  @box_type ||= begin
    # Returns `/Users/schisamo/dev/code/schisamo/vagrant-omnibus/test/acceptance/vmware_fusion`
    full_dir = File.dirname(File.expand_path(__FILE__))
    # Returns `vmware_fusion`
    base_dir = full_dir.split("/").last
    base_dir.split("_").first
  end
end

Vagrant.configure("2") do |config|

  config.vm.define :new_chef do |new_chef_config|
    new_chef_config.vm.box = "opscode-ubuntu-12.04"
    new_chef_config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/#{box_type}/opscode_ubuntu-12.04_chef-provisionerless.box"

    new_chef_config.omnibus.chef_version = :latest

    new_chef_config.vm.provision :chef_solo do |chef|
      chef.cookbooks_path = File.expand_path("../../../support/cookbooks", __FILE__)
      chef.add_recipe "chef-inator"
    end
  end

  config.vm.define :old_chef do |old_chef_config|
    old_chef_config.vm.box = "opscode-centos-6.5"
    old_chef_config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/#{box_type}/opscode_centos-6.5_chef-provisionerless.box"

    old_chef_config.omnibus.chef_version = "10.24.0"

    old_chef_config.vm.provision :chef_solo do |chef|
      chef.cookbooks_path = File.expand_path("../../../support/cookbooks", __FILE__)
      chef.add_recipe "chef-inator"
    end
  end

  # We don't have legacy VMware boxes
  unless box_type == "vmware"
    config.vm.define :chef_already_installed do |installed_config|
      installed_config.vm.box = "opscode-ubuntu-12.04-chef-11.4.4"
      installed_config.vm.box_url = "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_chef-11.4.4.box"

      installed_config.omnibus.chef_version = "11.4.4"

      installed_config.vm.provision :chef_solo do |chef|
        chef.cookbooks_path = File.expand_path("../../../support/cookbooks", __FILE__)
        chef.add_recipe "chef-inator"
      end
    end
  end

  config.vm.define :chef_on_windows do |win_config|
    # win_config.vm.guest             = :windows
    win_config.vm.box               = "win7x64-pro"
    # build this yourself https://github.com/misheska/basebox-packer
    # win_config.vm.box_url           = ''
    win_config.vm.boot_timeout      = 500

    win_config.omnibus.chef_version = :latest

    win_config.vm.provision :chef_solo do |chef|
      chef.cookbooks_path = File.expand_path("../../../support/cookbooks", __FILE__)
      chef.add_recipe "chef-inator"
    end
  end

  config.vm.define :no_bash do |c|
    c.vm.box = "opscode-freebsd-9.2"
    c.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/#{box_type}/opscode_freebsd-9.2_chef-provisionerless.box"
    c.omnibus.chef_version = :latest

    c.vm.synced_folder ".", "/vagrant", type: "rsync", id: "vagrant-root"

    # This forces all remote commands to execute under `sh`. If we don't
    # add this config then all `chef` related commands will execute
    # with `bash` (which might not be installed).
    c.ssh.shell = "sh"

    c.vm.provision :chef_solo do |chef|
      chef.synced_folder_type = "rsync"
      chef.cookbooks_path = File.expand_path("../../../support/cookbooks", __FILE__)
      chef.add_recipe "chef-inator"
    end
  end
end