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

def local_cache(basebox_name)
  # Mount the apt cache from the host, so that it survives re-starts of the VM.
  cache_dir = Pathname.new(File.join("#{Dir.home}", ".cache", "vagrant", "apt", basebox_name))
  partial_dir = cache_dir.join("partial")
  partial_dir.mkpath unless partial_dir.exist?
  cache_dir
end

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"

  # 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 "../..", "/home/vagrant/lensfun"

  cache_dir = local_cache(config.vm.box)
  config.vm.synced_folder cache_dir, "/var/cache/apt/archives/"

  # 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.
  config.vm.provision "shell", inline: <<-SHELL
    sudo apt-get update
    sudo apt-get install -y git devscripts python-docutils
    sudo apt-get build-dep -y liblensfun0
  SHELL
end
