# A virtual machine to run https://github.com/google/oss-fuzz
Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/xenial64"

  config.vm.synced_folder "../..", "/host/ArduinoJson"
  config.vm.synced_folder "E:\\Git\\oss-fuzz", "/host/oss-fuzz"

  config.vm.network "forwarded_port", guest: 8001, host: 8001

  config.vm.provider "virtualbox" do |v|
    v.memory = 2048
    v.cpus = 2
  end

  config.vm.provision "shell", privileged: false, inline: <<-SHELL
    set -x

    sudo apt-get update
    sudo apt-get install -y make git docker.io zip
    sudo groupadd docker
    sudo usermod -aG docker $USER

    git clone https://github.com/google/fuzzer-test-suite.git FTS
    ./FTS/tutorial/install-deps.sh  # Get deps
    ./FTS/tutorial/install-clang.sh # Get fresh clang binaries

    echo "export PROJECT_NAME='arduinojson'" >> $HOME/.profile
    echo "export CC='clang'" >> $HOME/.profile
    echo "export CXX='clang++'" >> $HOME/.profile
    echo "export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/" >> $HOME/.profile

    echo "Run /host/ArduinoJson/fuzzing/fuzz.sh" | sudo tee /etc/motd
  SHELL
end
