bitcore-install/btcp_store_demo.sh

333 lines
7.3 KiB
Bash
Raw Permalink Normal View History

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=$1
2018-04-11 09:28:36 -07:00
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 swapfile? EC2 Micro has limited RAM."
echo "1) 1GB - recommended for running Bitcore + MongoDB"
echo "2) 3GB - required when building btcpd from source"
echo "3) No Swapfile - not recommended on EC2 Micro"
read -r -p "[1/2/3] " response
2018-04-17 20:00:03 -07:00
case "$response" in
[1])
make_swapfile 1024
;;
[2])
make_swapfile 3072
;;
*)
echo "Not creating swapfile."
;;
2018-04-17 20:00:03 -07:00
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
}
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
local RPCPASSWORD=$(openssl rand -base64 32 | tr -d /=+ | cut -c -30)
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
showmetrics=0
2018-04-27 05:16:56 -07:00
EOF
2018-04-11 09:25:08 -07:00
fi
2018-04-17 20:00:03 -07:00
}
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
}
# 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 12:36:16 -07:00
cd ~/.btcprivate
2018-04-19 12:48:48 -07:00
local FILE="blockchain-explorer.tar.gz"
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"
wget -c https://github.com/BTCPrivate/BitcoinPrivate/releases/download/${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() {
# 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
# 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:
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 ch4ot1c/store-demo #BTCPrivate/insight-api-btcp BTCPrivate/insight-ui-btcp BTCPrivate/store-demo BTCPrivate/address-watch, BTCPrivate/bitcore-wallet-service (untested)
2018-04-19 12:48:48 -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",
"$BITCORE_SERVICE_APP",
2018-04-06 11:21:44 -07:00
"web"
],
"servicesConfig": {
"bitcoind": {
"spawn": {
"datadir": "$HOME/.btcprivate",
"exec": "$HOME/BitcoinPrivate/src/btcpd"
}
},
"store-demo": {
2018-05-15 23:13:03 -07:00
"mongoURL": "mongodb://localhost:27017/store-demo"
}
2018-04-06 10:23:12 -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/x.key",
#"certificateFile": "/etc/ssl/x.crt",
2018-04-19 11:40:33 -07:00
2018-04-06 10:23:12 -07:00
}
install_bower_browserify_uglify_js_libs() {
2018-05-15 23:13:03 -07:00
echo "Globally installing bower, browserify, uglify"
npm install -g bower browserify uglify
2018-05-02 13:27:00 -07:00
cd ~/btcp-explorer/node_modules/store-demo
bower install
2018-05-15 23:13:03 -07:00
# Build bitcore-lib.js + uglify + copy to widget's js/ dir
cd node_modules/bitcore-lib
browserify --require ./index.js:bitcore-lib -o bitcore-lib.js
2018-05-15 23:13:03 -07:00
uglify -s bitcore-lib.js -o bitcore-lib.min.js
cp {bitcore-lib.js,bitcore-lib.min.js} ~/btcp-explorer/node_modules/store-demo/static/js/bitcore-lib
bower install --allow-root
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-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
echo ---
2018-04-18 07:59:02 -07:00
echo ""
2018-05-02 13:27:00 -07:00
echo "BTCP Merchant Backend Setup - Installing dependencies."
echo ""
echo ---
install_ubuntu
2018-04-11 11:40:33 -07:00
echo ""
prompt_swapfile
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 ""
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
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
init_btcprivate_dotdir
2018-04-06 10:23:12 -07:00
fetch_btcp_blockchain
install_nvm_npm
2018-04-06 10:23:12 -07:00
2018-04-16 15:33:19 -07:00
install_mongodb
cd ~
install_bitcore
2018-04-06 10:23:12 -07:00
2018-05-15 23:13:03 -07:00
install_bower_browserify_uglify_js_libs
cd ~
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
echo "To start the daemon + its interfaces, run:"
2018-05-02 14:22:38 -07:00
echo "cd ~/btcp-explorer; ./bitcore-node start"
2018-04-11 11:40:33 -07:00
echo ""
echo "Runs on port $PORT (bitcore-node.json)."
2018-04-19 11:40:33 -07:00
echo ""
2018-05-15 23:13:03 -07:00
echo "Note - MongoDB needs to be running in the background for store-demo:"
echo "mongod &"
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