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


Vagrant.configure("2") do |config|
  # All Vagrant configuration is done here. The most common configuration
  # options are documented and commented below. For a complete reference,
  # please see the online documentation at vagrantup.com.

  # Every Vagrant virtual environment requires a box to build off of.
  # In this case Ubuntu Server 12.04 i386
  config.vm.box = "ubuntu/trusty32"

  # Forward a port from the guest to the host, which allows for outside
  # computers to access the VM, whereas host only networking does not.
  config.vm.network :forwarded_port, guest: 80, host:8080

  # Provisioning via shell, update to avoid "IP address not found" etc.
  config.vm.provision :shell, :inline => "sudo apt-get update"
  # Provisioning via shell, only the basics fo BicBucStriim
  config.vm.provision :shell, :inline => "sudo apt-get -y install apache2 php5 sqlite3 php5-sqlite php5-gd tmux"
  # Enable mod_rewrite
  config.vm.provision :shell, :inline => "sudo a2enmod rewrite"
  # Send a host config with "AllowOverride All" to enable .htaccess/mod_rewrite
  # By default AllowOverride is set to None
  config.vm.provision :shell, :inline => "sudo cp /vagrant/default /etc/apache2/sites-available/000-default.conf"
  config.vm.provision :shell, :inline => "sudo service apache2 restart"
  # Make the dir for the calibre library
  config.vm.provision :shell, :inline => "sudo mkdir /tmp/calibre; sudo chown vagrant:vagrant /tmp/calibre"
  # Make the dir for the app
  config.vm.provision :shell, :inline => "sudo mkdir /var/www/bbs; sudo chown vagrant:vagrant /var/www/bbs"
  # Copy the tmux config
  config.vm.provision :shell, :inline => "cp /vagrant/tmux.conf /home/vagrant/.tmux.conf"

  # Create the environment for BicBucStrim on the server.
  # The web server path "/bbs" is mapped to the local directory "tests/work/src". 
  # The Calibre library for the tests is in "tests/work/calibre" and will be mapped to "/tmp/calibre"
  config.vm.synced_folder "../work/src", "/var/www/bbs"
  config.vm.synced_folder "../work/calibre", "/tmp/calibre"
end
