# Emacs, this is in -*- ruby -*-
#
# The directory one up from here is synced with /vagrant in the VM.
# The intended usage is
#
#   cd /path/to/your/TuLiP-sources
#   cd contrib
#   vagrant up
#   vagrant ssh
#   cd /vagrant
#
# From there, it remains to install the polytope package and then link
# to your local TuLiP sourcetree. E.g.,
#
#   sudo pip install polytope
#   sudo pip install -e .

install_dependencies = <<-SHELL
#!/bin/sh -e
sudo apt-get -y update
sudo apt-get -y install python-pip python-nose
sudo apt-get -y install python-numpy python-networkx python-scipy python-ply python-matplotlib
sudo apt-get -y install python-pydot
sudo apt-get -y install libglpk-dev
sudo apt-get -y install bison flex
sudo apt-get -y install default-jre

if [ ! -f cvxopt-1.1.7.tar.gz ]
then
    curl -sL https://github.com/cvxopt/cvxopt/archive/1.1.7.tar.gz -o cvxopt-1.1.7.tar.gz
fi
FILECHECKSUM=`shasum -a 256 cvxopt-1.1.7.tar.gz|cut -d ' ' -f1`
if [ $FILECHECKSUM != '11624199ba0064e4c384c9fe7ced6d425596fe1f1bbfafd6baaa18f0fe63fd9b' ]
then
    echo "Checksum for the cvxopt tarball does not have expected value."
    false
fi
tar -xzf cvxopt-1.1.7.tar.gz
cd cvxopt-1.1.7
sed -i.orig '41s/BUILD_GLPK = 0/BUILD_GLPK = 1/' setup.py
python setup.py build
sudo pip install .
cd ..

gpg --keyserver pgp.mit.edu --recv-keys 03B40F63

CUDDVERSION=2.5.0
GR1CVERSION=0.10.1

if [ ! -f gr1c-$GR1CVERSION.tar.gz -o ! -f gr1c-$GR1CVERSION.tar.gz.sig ]
then
    curl -sO http://vehicles.caltech.edu/snapshots/gr1c/gr1c-$GR1CVERSION.tar.gz
    curl -sO http://vehicles.caltech.edu/snapshots/gr1c/gr1c-$GR1CVERSION.tar.gz.sig
fi
gpg --verify gr1c-$GR1CVERSION.tar.gz.sig
FILECHECKSUM=`shasum -a 256 gr1c-$GR1CVERSION.tar.gz|cut -d ' ' -f1`
if [ $FILECHECKSUM != '73699369ee55b95aeb3742504e27676491b6d23db176e7e84c266e1a4845c6a3' ]
then
    echo "Checksum for the gr1c tarball does not have expected value."
    false
fi
tar -xzf gr1c-$GR1CVERSION.tar.gz
cd gr1c-$GR1CVERSION
./get-deps.sh
make cudd
make all
make check
sudo make install


SHELL

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.provision "shell", inline: install_dependencies
  config.vm.synced_folder "..", "/vagrant"
end
