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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # define machine in specific scope so that we can have a machines active
  # from multiple git branches.
  config.vm.define "ehx", primary: true do |machine|
    # Every Vagrant development environment requires a box. You can search for
    # boxes at https://atlas.hashicorp.com/search.
    machine.vm.box = "centos/7"
    machine.vm.box_version = "1611.01"

    machine.vm.hostname = "ehx"

    # Create a forwarded port mapping which allows access to a specific port
    # within the machine from a port on the host machine. In the example below,
    # accessing "localhost:8080" will access port 80 on the guest machine.
    # config.vm.network "forwarded_port", guest: 80, host: 8080
    machine.vm.network "forwarded_port", guest: 7001, host: 7001, host_ip: "localhost"
    machine.vm.network "forwarded_port", guest: 7002, host: 7002, host_ip: "localhost"
    machine.vm.network "forwarded_port", guest: 1521, host: 7521, host_ip: "localhost"
    machine.vm.network "forwarded_port", guest: 4000, host: 7004, host_ip: "localhost"

    # Share an additional folder to the guest VM. The first argument is
    # the path on the host to the actual folder. The second argument is
    # the path on the guest to mount the folder. And the optional third
    # argument is a set of non-required options.
    # config.vm.synced_folder "../data", "/vagrant_data"
    machine.vm.synced_folder ".", "/vagrant", disabled: true
    machine.vm.synced_folder ".", "/ehx", type: "virtualbox"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
    machine.vm.provider "virtualbox" do |vb|
      vb.name = "ehx"
    #   # Display the VirtualBox GUI when booting the machine
    #   vb.gui = true
    #
    #   # Customize the amount of memory on the VM:
      vb.memory = "4096"

      if !File.exists?(".vagrant/ehx-swap.vmdk") then
        vb.customize ["createmedium", "disk", "--filename", ".vagrant/ehx-swap.vmdk", "--size", "3072", "--format", "VMDK"]
        vb.customize ["storageattach", :id, "--storagectl", "IDE", "--port", "0", "--device", "1", "--type", "hdd", "--medium", ".vagrant/ehx-swap.vmdk"]
      end
    end

    # ssh login using username/password (uncomment if you're using Vagrant 1.85).
    #machine.ssh.username = "vagrant"
    #machine.ssh.password = "vagrant"
    #machine.ssh.insert_key = true
    machine.ssh.forward_agent = true
    machine.ssh.forward_x11 = true

    # set auto_update to false, if you do NOT want to check the correct 
    # additions version when booting this machine
    machine.vbguest.auto_update = true

    # do NOT download the iso file from a webserver
    machine.vbguest.no_remote = true

    # Enable provisioning with a shell script. Additional provisioners such as
    # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
    # documentation for more information about their specific syntax and use.
    machine.vm.provision "shell", inline: <<-SHELL
     . /ehx/vagrant-scripts/provision.sh
    SHELL
 end
end
