#!/bin/bash

sudo apt-get --quiet --assume-yes update
sudo apt-get --quiet --assume-yes upgrade

sudo apt-get --quiet --assume-yes install build-essential
sudo apt-get --quiet --assume-yes install gdb
sudo apt-get --quiet --assume-yes install gcc-multilib
sudo apt-get --quiet --assume-yes install zsh
sudo apt-get --quiet --assume-yes install libncurses5 libncurses5-dev libncursesw5 libncurses5:i386

sudo apt-get --assume-yes --quiet install git libssl-dev libffi-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev

## pyenv
cd /home/vagrant/ && curl https://pyenv.run | bash
echo 'export PATH="/home/vagrant/.pyenv/bin:$PATH"' >> /home/vagrant/.bashrc
echo 'eval "$(pyenv init -)"' >> /home/vagrant/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> /home/vagrant/.bashrc

export PATH="/home/vagrant/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

pyenv install 3.9.0
pyenv global 3.9.0

python3 -m pip install --upgrade setuptools
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade pwntools
python3 -m pip uninstall --yes ROPgadget

cd /home/vagrant/cw && ./ropinstall.sh

python3 -m pip install --upgrade keystone-engine capstone filebytes pyvex
cd /home/vagrant/cw && git clone https://github.com/sashs/Ropper.git
cd /home/vagrant/cw/Ropper && git submodule init && git submodule update
cd /home/vagrant/ && git clone https://github.com/Z3Prover/z3.git && cd z3 && python3 scripts/mk_make.py && cd build && make -j$(nproc) && sudo make install
cp -R /home/vagrant/z3/build/python/z3 /home/vagrant/cw/Ropper


sudo apt-get clean

echo ":)"