#!/bin/bash
mode="release"

function release_ {
cd /home/wareck/
wget -c https://bitcoincore.org/bin/bitcoin-core-23.0/bitcoin-23.0.tar.gz
tar xvfz bitcoin-23.0.tar.gz
cd bitcoin-23.0
cd depends
make download
make
cd ..
./autogen.sh
CONFIG_SITE=/home/wareck/bitcoin-23.0/depends/x86_64-pc-linux-gnu/share/config.site ./configure --prefix=/home/wareck/bitcoin_binary
make
make install
cd /home/wareck/
rm bitcoin-23.0.tar.gz

}

function dev_ {
cd /home/wareck
if [ -d bitcoin ]
then
cd bitcoin
git pull
else
git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
git reset --hard a46e17832fd2ecc44943ff7ccff8af443f6239b8
fi
sudo apt-get update
sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils -y
sudo apt-get install libboost-all-dev libdb-dev libdb++-dev libminiupnpc-dev libgoogle-perftools-dev libzmq3-dev -y
cd depends
make download
make
cd ..
./autogen.sh
CONFIG_SITE=/home/wareck/bitcoin/depends/x86_64-pc-linux-gnu/share/config.site ./configure --prefix=/home/wareck/bitcoin_binary
make -j 4
make install
}

if [ $mode = "dev" ]
then
echo "Building Bitcoin devel"
dev_
else
echo -e "Building Bitcoin release 0.23\n"
release_
fi
