#!/bin/bash

# https://github.com/biblepay/biblepay-evolution/blob/master/BuildBiblePay.txt

sudo add-apt-repository universe -y
sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils
sudo apt-get install libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev
sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler
sudo apt-get install git
sudo apt-get install curl build-essential libtool autotools-dev automake pkg-config python3 bsdmainutils cmake
sudo add-apt-repository ppa:bitcoin/bitcoin -y
sudo apt-get update -y
sudo apt-get install libdb4.8-dev libdb4.8++-dev
sudo apt-get upgrade -y

# Main Directory
wdir=$HOME"/biblepay-evolution"
cd $HOME

git clone http://github.com/biblepay/biblepay-evolution
prefix=x86_64-pc-linux-gnu
cd $wdir/depends

# Build with all cores, depending on the number of CPU cores available
cores=`lscpu | grep "^CPU(s):" | awk -F" " '{print $2}'`
make -j$cores

cd $wdir
./autogen.sh
./configure --prefix $wdir/depends/x86_64-pc-linux-gnu
make  # It tends to hang/crash if you use all cores on certain VPSs

# Make biblepay.conf in .biblepayevolution
evo=$HOME"/.biblepayevolution"
mkdir $evo
conf=$evo"/biblepay.conf"
echo "testnet=1" > $conf
echo "debug=1" >> $conf

echo "Completed..."


echo "To run commmand-line interface (CLI) : "$HOME"/biblepay-evolution/src/biblepay-cli -testnet"
echo "To run graphical user interface (GUI): "$HOME"/biblepay-evolution/src/qt/biblepay-qt -testnet"
echo "                                     : you need to login using ssh -Y username@server before running graphical interface" 


