2018-04-06 10:23:12 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-04-11 09:28:36 -07:00
|
|
|
# !!! EC2 - Make sure port 8001 is in your security group
|
2018-04-19 11:40:33 -07:00
|
|
|
|
|
|
|
# !!! Run this in a fresh environment.
|
2018-04-11 09:28:36 -07:00
|
|
|
|
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-17 20:00:03 -07:00
|
|
|
# You must have enough memory for the BTCP build to succeed.
|
2018-04-11 11:40:33 -07:00
|
|
|
|
2018-04-17 20:00:03 -07:00
|
|
|
local 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-17 20:00:03 -07:00
|
|
|
prompt_swapfile() {
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Can we make you a 3gb swapfile? EC2 Micro needs it because it takes a lot of memory to build BTCP."
|
|
|
|
echo ""
|
|
|
|
read -r -p "[y/N] " response
|
|
|
|
case "$response" in
|
|
|
|
[yY][eE][sS]|[yY])
|
|
|
|
make_swapfile
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Not creating swapfile."
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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-17 20:11:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
init_btcprivate_dotdir() {
|
|
|
|
|
2018-04-17 20:00:03 -07:00
|
|
|
# Make .btcprivate dir (btcpd hasn't been run)
|
2018-04-13 08:46:39 -07:00
|
|
|
if [ ! -e ~/.btcprivate/ ]
|
|
|
|
then
|
|
|
|
mkdir ~/.btcprivate
|
|
|
|
fi
|
2018-04-13 11:19:29 -07:00
|
|
|
|
2018-04-17 20:00:03 -07:00
|
|
|
# Make empty btcprivate.conf if needed; otherwise use existing
|
2018-04-11 09:25:08 -07:00
|
|
|
if [ ! -e ~/.btcprivate/btcprivate.conf ]
|
|
|
|
then
|
2018-04-27 05:16:56 -07:00
|
|
|
|
2018-04-27 08:28:28 -07:00
|
|
|
local RPCPASSWORD=$(head -c 32 /dev/urandom | base64)
|
2018-04-27 05:16:56 -07:00
|
|
|
touch ~/.btcprivate/btcprivate.conf
|
|
|
|
cat << EOF > ~/.btcprivate/btcprivate.conf
|
|
|
|
#gen=1
|
|
|
|
#reindex=1
|
|
|
|
#showmetrics=0
|
|
|
|
#rpcport=7932
|
|
|
|
rpcuser=bitcoin
|
2018-04-27 08:28:28 -07:00
|
|
|
rpcpassword=$RPCPASSWORD
|
2018-04-27 05:16:56 -07:00
|
|
|
server=1
|
|
|
|
whitelist=127.0.0.1
|
|
|
|
txindex=1
|
|
|
|
addressindex=1
|
|
|
|
timestampindex=1
|
|
|
|
spentindex=1
|
|
|
|
zmqpubrawtx=tcp://127.0.0.1:28332
|
|
|
|
zmqpubhashblock=tcp://127.0.0.1:28332
|
|
|
|
rpcallowip=127.0.0.1
|
|
|
|
uacomment=bitcore
|
|
|
|
addnode=dnsseed.btcprivate.org
|
2018-05-02 11:15:21 -07:00
|
|
|
showmetrics=0
|
2018-04-27 05:16:56 -07:00
|
|
|
EOF
|
|
|
|
|
2018-04-11 09:25:08 -07:00
|
|
|
fi
|
|
|
|
|
2018-04-17 20:11:44 -07:00
|
|
|
cd ~/.btcprivate
|
|
|
|
|
2018-04-19 11:40:33 -07:00
|
|
|
# Download + decompress blockchain.tar.gz (blocks/, chainstate/) to quickly sync past block 300,000
|
2018-04-17 20:00:03 -07:00
|
|
|
fetch_btcp_blockchain
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-19 13:52:09 -07:00
|
|
|
fetch_zcash_params() {
|
|
|
|
|
|
|
|
wget -qO- https://raw.githubusercontent.com/BTCPrivate/BitcoinPrivate/master/btcputil/fetch-params.sh | bash
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-17 20:00:03 -07:00
|
|
|
fetch_btcp_blockchain() {
|
|
|
|
|
2018-04-19 12:36:16 -07:00
|
|
|
cd ~/.btcprivate
|
|
|
|
|
2018-04-19 12:48:48 -07:00
|
|
|
local FILE="blockchain-explorer.tar.gz"
|
2018-04-27 23:55:28 -07:00
|
|
|
wget -c https://storage.googleapis.com/btcpblockchain/$FILE
|
2018-04-19 12:36:16 -07:00
|
|
|
tar -zxvf $FILE
|
2018-04-17 20:00:03 -07:00
|
|
|
echo "Downloading and extracting blockchain files - Done."
|
2018-04-19 12:36:16 -07:00
|
|
|
rm -rf $FILE
|
2018-04-17 20:00:03 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch_btcp_binaries() {
|
|
|
|
|
|
|
|
mkdir -p ~/BitcoinPrivate/src
|
|
|
|
cd ~/BitcoinPrivate/src
|
|
|
|
|
2018-04-27 12:16:28 -07:00
|
|
|
local RELEASE="1.0.12"
|
|
|
|
local COMMIT="69aa9ce"
|
2018-04-19 12:48:48 -07:00
|
|
|
local FILE="btcp-${RELEASE}-explorer-${COMMIT}-linux.tar.gz"
|
2018-04-27 23:55:28 -07:00
|
|
|
wget -c https://github.com/BTCPrivate/BitcoinPrivate/releases/download/v${RELEASE}-${COMMIT}/${FILE}
|
2018-04-19 11:40:33 -07:00
|
|
|
tar -zxvf $FILE
|
2018-04-17 20:00:03 -07:00
|
|
|
echo "Downloading and extracting BTCP files - Done."
|
2018-04-19 11:40:33 -07:00
|
|
|
rm -rf $FILE
|
2018-04-13 08:46:39 -07:00
|
|
|
|
2018-04-06 10:23:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
install_nvm_npm() {
|
|
|
|
|
2018-04-17 20:00:03 -07:00
|
|
|
cd ~
|
|
|
|
|
2018-04-27 23:55:28 -07:00
|
|
|
# Install npm
|
2018-04-11 09:25:08 -07:00
|
|
|
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
|
2018-04-17 20:00:03 -07:00
|
|
|
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
2018-04-06 10:23:12 -07:00
|
|
|
|
2018-05-02 14:11:04 -07:00
|
|
|
# Install node v4 (as the default)
|
2018-04-11 09:25:08 -07:00
|
|
|
nvm install v4
|
|
|
|
nvm use v4
|
|
|
|
nvm alias default v4
|
2018-04-06 10:23:12 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-17 20:00:03 -07:00
|
|
|
# MongoDB dependency for bitcore:
|
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)
|
2018-04-19 12:48:48 -07:00
|
|
|
../node_modules/bitcore-node-btcp/bin/bitcore-node install BTCPrivate/insight-api-btcp BTCPrivate/insight-ui-btcp BTCPrivate/store-demo # BTCPrivate/address-watch, BTCPrivate/bitcore-wallet-service (untested)
|
|
|
|
|
2018-05-02 14:11:04 -07:00
|
|
|
# Symlink to bitcore-node to btcp-explorer dir
|
|
|
|
ln -s node_modules/bitcore-node-btcp/bin/bitcore-node bitcore-node
|
|
|
|
|
2018-04-19 12:48:48 -07:00
|
|
|
local BITCORE_SERVICE_APP="store-demo" #address-watch, bitcore-wallet-service
|
2018-05-02 13:27:00 -07:00
|
|
|
local PORT=8001
|
2018-04-06 11:21:44 -07:00
|
|
|
|
|
|
|
# Create config file for Bitcore
|
|
|
|
cat << EOF > bitcore-node.json
|
|
|
|
{
|
|
|
|
"network": "livenet",
|
2018-05-02 13:27:00 -07:00
|
|
|
"port": $PORT,
|
2018-04-06 11:21:44 -07:00
|
|
|
"services": [
|
|
|
|
"bitcoind",
|
|
|
|
"insight-api-btcp",
|
|
|
|
"web"
|
|
|
|
],
|
|
|
|
"servicesConfig": {
|
|
|
|
"bitcoind": {
|
|
|
|
"spawn": {
|
|
|
|
"datadir": "$HOME/.btcprivate",
|
|
|
|
"exec": "$HOME/BitcoinPrivate/src/btcpd"
|
2018-04-10 12:37:41 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"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-19 11:40:33 -07:00
|
|
|
#TODO Prompt option + Automate SSL Setup (LetsEncrypt)
|
|
|
|
#"https": true,
|
|
|
|
#"privateKeyFile": "/etc/ssl/bws.bitpay.com.key",
|
|
|
|
#"certificateFile": "/etc/ssl/bws.bitpay.com.crt",
|
|
|
|
|
2018-04-06 10:23:12 -07:00
|
|
|
}
|
|
|
|
|
2018-04-27 06:41:34 -07:00
|
|
|
install_bower_browserify_js_libs() {
|
2018-05-02 14:11:04 -07:00
|
|
|
echo "Globally installing bower, browserify"
|
|
|
|
npm install -g bower browserify
|
|
|
|
#sudo npm install -g pm2
|
2018-05-02 13:27:00 -07:00
|
|
|
|
|
|
|
# Build bitcore-lib-btcp.js + copy to invoice server's js/ dir
|
2018-04-27 06:41:34 -07:00
|
|
|
cd ~/btcp-explorer/node_modules/store-demo
|
|
|
|
bower install
|
|
|
|
cd node_modules/bitcore-lib-btcp
|
|
|
|
browserify --require ./index.js:bitcore-lib-btcp -o bitcore-lib-btcp.js
|
2018-04-27 06:57:16 -07:00
|
|
|
cp bitcore-lib-btcp.js ~/btcp-explorer/node_modules/store-demo/static/js/bitcore-lib-btcp
|
2018-04-27 06:41:34 -07:00
|
|
|
}
|
2018-04-17 20:00:03 -07:00
|
|
|
|
2018-05-02 13:27:00 -07:00
|
|
|
|
2018-04-17 20:00:03 -07:00
|
|
|
run_install() {
|
2018-04-11 09:25:08 -07:00
|
|
|
|
2018-04-18 07:59:02 -07:00
|
|
|
echo ""
|
2018-05-02 13:27:00 -07:00
|
|
|
echo "BTCP Merchant Backend Setup - Installing dependencies."
|
2018-04-11 11:40:33 -07:00
|
|
|
echo ""
|
|
|
|
|
2018-04-19 12:53:12 -07:00
|
|
|
install_ubuntu > /dev/null
|
2018-04-11 11:40:33 -07:00
|
|
|
|
2018-04-18 07:59:02 -07:00
|
|
|
echo ""
|
2018-04-19 11:40:33 -07:00
|
|
|
echo "How would you like to fetch BTCP (btcpd and btcp-cli):"
|
|
|
|
echo "1) [fast] Download the latest binaries"
|
|
|
|
echo "2) [slow] Download + build from source code"
|
2018-04-11 11:40:33 -07:00
|
|
|
echo ""
|
2018-04-18 09:38:03 -07:00
|
|
|
read -r -p "[1/2] " response
|
2018-04-11 09:25:08 -07:00
|
|
|
case "$response" in
|
2018-04-17 20:00:03 -07:00
|
|
|
[1])
|
2018-04-19 13:52:09 -07:00
|
|
|
fetch_zcash_params
|
2018-04-19 11:40:33 -07:00
|
|
|
fetch_btcp_binaries
|
2018-04-11 09:25:08 -07:00
|
|
|
;;
|
2018-04-17 20:00:03 -07:00
|
|
|
[2])
|
2018-04-19 11:40:33 -07:00
|
|
|
prompt_swapfile
|
|
|
|
clone_and_build_btcp
|
2018-04-11 09:25:08 -07:00
|
|
|
;;
|
2018-04-17 20:00:03 -07:00
|
|
|
*)
|
|
|
|
echo "Neither; Skipped."
|
2018-04-18 07:59:02 -07:00
|
|
|
;;
|
2018-04-11 09:25:08 -07:00
|
|
|
esac
|
2018-04-06 11:21:44 -07:00
|
|
|
|
2018-04-17 20:11:44 -07:00
|
|
|
init_btcprivate_dotdir
|
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-27 06:41:34 -07:00
|
|
|
install_bower_browserify_js_libs
|
|
|
|
|
2018-05-02 13:27:00 -07:00
|
|
|
echo "Installation 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
|
2018-04-18 07:59:02 -07:00
|
|
|
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
2018-04-11 09:28:36 -07:00
|
|
|
|
2018-05-02 14:11:04 -07:00
|
|
|
echo "To start the daemon + its interfaces, run:"
|
|
|
|
echo "cd ~/btcp-explorer; bitcore-node start"
|
2018-04-11 11:40:33 -07:00
|
|
|
echo ""
|
2018-05-02 14:11:04 -07:00
|
|
|
echo "Runs on port $PORT (bitcore-node.json)."
|
2018-04-19 11:40:33 -07:00
|
|
|
echo ""
|
2018-04-17 20:00:03 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-19 11:40:33 -07:00
|
|
|
|
|
|
|
# *** SCRIPT START ***
|
2018-04-17 20:00:03 -07:00
|
|
|
|
|
|
|
cd ~
|
|
|
|
run_install
|
|
|
|
|