2018-04-06 10:23:12 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-04-11 09:25:08 -07:00
|
|
|
# BTCP Bitcore API + Explorer + Store / AddressWatch Demo
|
2018-04-06 10:23:12 -07:00
|
|
|
|
2018-04-11 09:28:36 -07:00
|
|
|
# !!! EC2 - Make sure port 8001 is in your security group
|
|
|
|
|
2018-04-06 10:23:12 -07:00
|
|
|
install_ubuntu() {
|
2018-04-11 09:25:08 -07:00
|
|
|
|
2018-04-06 11:21:44 -07:00
|
|
|
# Get Ubuntu Dependencies
|
|
|
|
sudo apt-get update
|
2018-04-06 10:23:12 -07:00
|
|
|
|
2018-04-06 11:21:44 -07:00
|
|
|
sudo apt-get -y install \
|
|
|
|
build-essential pkg-config libc6-dev m4 g++-multilib \
|
|
|
|
autoconf libtool ncurses-dev unzip git python \
|
|
|
|
zlib1g-dev wget bsdmainutils automake
|
2018-04-06 10:23:12 -07:00
|
|
|
|
2018-04-11 09:25:08 -07:00
|
|
|
# Install ZeroMQ libraries (Bitcore)
|
|
|
|
sudo apt-get -y install libzmq3-dev
|
2018-04-11 11:40:33 -07:00
|
|
|
|
2018-04-06 10:23:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-11 09:25:08 -07:00
|
|
|
make_swapfile() {
|
|
|
|
|
2018-04-11 11:40:33 -07:00
|
|
|
# You must have enough memory for the installation to succeed.
|
|
|
|
|
|
|
|
PREV=$PWD
|
2018-04-11 09:28:36 -07:00
|
|
|
cd /
|
|
|
|
sudo dd if=/dev/zero of=swapfile bs=1M count=3000
|
|
|
|
sudo mkswap swapfile
|
|
|
|
sudo chmod 0600 /swapfile
|
|
|
|
sudo swapon swapfile
|
|
|
|
echo "/swapfile none swap sw 0 0" | sudo tee -a etc/fstab > /dev/null
|
2018-04-11 11:40:33 -07:00
|
|
|
cd $PREV
|
2018-04-11 09:25:08 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-06 10:23:12 -07:00
|
|
|
clone_and_build_btcp() {
|
2018-04-11 09:25:08 -07:00
|
|
|
|
|
|
|
# Clone latest Bitcoin Private source, and checkout explorer-btcp
|
2018-04-16 15:33:19 -07:00
|
|
|
if [ ! -e ~/BitcoinPrivate ]
|
|
|
|
then
|
|
|
|
git clone -b explorer-btcp https://github.com/BTCPrivate/BitcoinPrivate
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Freshen up
|
|
|
|
#git checkout explorer-btcp
|
|
|
|
#git checkout -- .
|
|
|
|
#git pull
|
2018-04-11 09:25:08 -07:00
|
|
|
|
|
|
|
# Fetch BTCP/Zcash ceremony params
|
2018-04-11 11:40:33 -07:00
|
|
|
./BitcoinPrivate/btcputil/fetch-params.sh
|
2018-04-11 09:25:08 -07:00
|
|
|
|
|
|
|
# Build Bitcoin Private
|
2018-04-11 11:40:33 -07:00
|
|
|
./BitcoinPrivate/btcputil/build.sh -j$(nproc)
|
2018-04-11 09:25:08 -07:00
|
|
|
|
2018-04-13 08:51:30 -07:00
|
|
|
#Make hidden .btcprivate dir because the daemon has not ran and created the folder yet
|
|
|
|
#Then download the blockchain zip and extract to speed up the initial syncing when first starting
|
2018-04-13 08:46:39 -07:00
|
|
|
if [ ! -e ~/.btcprivate/ ]
|
|
|
|
then
|
2018-04-13 08:51:30 -07:00
|
|
|
echo "Bitcoin Private Data Dir(.btcprivate) does not exist in the current user home directory, creating folder..."
|
2018-04-13 08:46:39 -07:00
|
|
|
mkdir ~/.btcprivate
|
|
|
|
fi
|
2018-04-13 10:49:40 -07:00
|
|
|
echo "Bitcoin Private Data Dir(.btcprivate) does exist in the current user home directory. Downloading and Extracting files"
|
|
|
|
cd ~/.btcprivate
|
|
|
|
wget https://storage.googleapis.com/btcpblockchain/blockchain.tar.gz
|
|
|
|
tar -zxvf blockchain.tar.gz
|
|
|
|
echo "Downloading and extracting of blockchain files completed"
|
2018-04-13 08:46:39 -07:00
|
|
|
|
2018-04-11 09:25:08 -07:00
|
|
|
# Make initial, empty btcprivate.conf if needed
|
|
|
|
if [ ! -e ~/.btcprivate/btcprivate.conf ]
|
|
|
|
then
|
|
|
|
touch ~/.btcprivate/btcprivate.conf
|
|
|
|
fi
|
|
|
|
|
2018-04-13 08:46:39 -07:00
|
|
|
|
|
|
|
|
2018-04-06 10:23:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
install_nvm_npm() {
|
|
|
|
|
2018-04-11 09:25:08 -07:00
|
|
|
# Install npm
|
|
|
|
sudo apt-get -y install npm
|
|
|
|
|
|
|
|
# Install nvm (npm version manager)
|
|
|
|
wget -qO- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
|
|
|
|
|
|
|
|
# Set up nvm
|
|
|
|
export NVM_DIR="$HOME/.nvm"
|
|
|
|
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
|
|
|
|
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
2018-04-06 10:23:12 -07:00
|
|
|
|
2018-04-11 09:25:08 -07:00
|
|
|
# Install node v4
|
|
|
|
nvm install v4
|
|
|
|
nvm use v4
|
|
|
|
nvm alias default v4
|
2018-04-06 10:23:12 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-11 09:25:08 -07:00
|
|
|
# MongoDB dependency for bitcore-wallet-service:
|
2018-04-10 12:37:41 -07:00
|
|
|
|
|
|
|
install_mongodb() {
|
|
|
|
|
|
|
|
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
|
|
|
|
# Ubuntu >= 16; for prior versions, see mongodb website
|
|
|
|
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
|
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y mongodb-org
|
|
|
|
|
|
|
|
# Make initial empty db dir
|
|
|
|
sudo mkdir -p /data/db
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-06 10:23:12 -07:00
|
|
|
install_bitcore() {
|
2018-04-06 11:21:44 -07:00
|
|
|
|
2018-04-16 15:33:19 -07:00
|
|
|
cd ~
|
|
|
|
|
2018-04-06 11:21:44 -07:00
|
|
|
# Install Bitcore (Headless)
|
|
|
|
npm install BTCPrivate/bitcore-node-btcp
|
|
|
|
|
|
|
|
# Create Bitcore Node
|
|
|
|
./node_modules/bitcore-node-btcp/bin/bitcore-node create btcp-explorer
|
|
|
|
cd btcp-explorer
|
|
|
|
|
|
|
|
# Install Insight API / UI (Explorer) (Headless)
|
|
|
|
../node_modules/bitcore-node-btcp/bin/bitcore-node install BTCPrivate/insight-api-btcp BTCPrivate/insight-ui-btcp BTCPrivate/store-demo
|
2018-04-11 09:28:36 -07:00
|
|
|
# (BTCPrivate/address-watch) (BTCPrivate/bitcore-wallet-service (untested))
|
2018-04-06 11:21:44 -07:00
|
|
|
|
|
|
|
|
|
|
|
# Create config file for Bitcore
|
|
|
|
cat << EOF > bitcore-node.json
|
|
|
|
{
|
|
|
|
"network": "livenet",
|
|
|
|
"port": 8001,
|
|
|
|
"services": [
|
|
|
|
"bitcoind",
|
|
|
|
"insight-api-btcp",
|
|
|
|
"insight-ui-btcp",
|
|
|
|
"store-demo",
|
|
|
|
"web"
|
|
|
|
],
|
|
|
|
"servicesConfig": {
|
|
|
|
"bitcoind": {
|
|
|
|
"spawn": {
|
|
|
|
"datadir": "$HOME/.btcprivate",
|
|
|
|
"exec": "$HOME/BitcoinPrivate/src/btcpd"
|
2018-04-10 12:37:41 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"insight-ui-btcp": {
|
|
|
|
"apiPrefix": "api",
|
|
|
|
"routePrefix": ""
|
|
|
|
},
|
|
|
|
"insight-api-btcp": {
|
|
|
|
"routePrefix": "api"
|
|
|
|
}
|
2018-04-06 10:23:12 -07:00
|
|
|
}
|
2018-04-10 12:37:41 -07:00
|
|
|
}
|
2018-04-06 11:21:44 -07:00
|
|
|
EOF
|
|
|
|
|
2018-04-06 10:23:12 -07:00
|
|
|
}
|
|
|
|
|
2018-04-11 11:40:33 -07:00
|
|
|
# -- Begin Fetching + Building --
|
2018-04-11 09:25:08 -07:00
|
|
|
cd ~
|
|
|
|
|
2018-04-06 11:21:44 -07:00
|
|
|
echo "Begin Setup."
|
2018-04-11 11:40:33 -07:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
install_ubuntu
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Can we make you a 3gb swapfile? EC2 Micro needs it because it takes a lot of memory to build BTCP."
|
|
|
|
echo ""
|
2018-04-11 09:25:08 -07:00
|
|
|
read -r -p "[y/N] " response
|
|
|
|
case "$response" in
|
|
|
|
[yY][eE][sS]|[yY])
|
|
|
|
make_swapfile
|
|
|
|
clone_and_build_btcp
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
clone_and_build_btcp
|
|
|
|
;;
|
|
|
|
esac
|
2018-04-06 11:21:44 -07:00
|
|
|
|
2018-04-06 10:23:12 -07:00
|
|
|
|
2018-04-13 08:47:41 -07:00
|
|
|
install_nvm_npm
|
2018-04-06 10:23:12 -07:00
|
|
|
|
2018-04-16 15:33:19 -07:00
|
|
|
install_mongodb
|
2018-04-10 12:37:41 -07:00
|
|
|
|
2018-04-13 08:47:41 -07:00
|
|
|
install_bitcore
|
2018-04-06 10:23:12 -07:00
|
|
|
|
2018-04-06 11:21:44 -07:00
|
|
|
echo "Complete."
|
2018-04-11 11:40:33 -07:00
|
|
|
echo ""
|
|
|
|
|
|
|
|
# Verify that nvm is exported
|
|
|
|
export NVM_DIR="$HOME/.nvm"
|
|
|
|
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
|
|
|
|
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
2018-04-11 09:28:36 -07:00
|
|
|
|
2018-04-10 12:37:41 -07:00
|
|
|
echo "To start mongodb for bitcore-wallet-service, run 'mongod &'"
|
2018-04-11 11:40:33 -07:00
|
|
|
echo "To start the bitcore-node, run:"
|
|
|
|
echo "cd ~/btcp-explorer; nvm use v4; ./node_modules/bitcore-node-btcp/bin/bitcore-node start"
|
|
|
|
echo ""
|
2018-04-06 10:23:12 -07:00
|
|
|
echo "To view the explorer in your browser - http://server_ip:8001"
|
2018-04-06 11:21:44 -07:00
|
|
|
echo "For https, we recommend you route through Cloudflare. bitcore-node also supports it via the config; provide certs."
|