#!/bin/bash # ESBC Masternode Setup Script V1 for linux # Script will attempt to autodetect primary public IP address # and generate masternode private key unless specified in command line # Usage: # bash install #Color codes RED='\033[0;91m' GREEN='\033[1;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color #TCP port PORT=32322 RPC=32323 #Clear keyboard input buffer function clear_stdin { while read -r -t 0; do read -r; done; } #Delay script execution for N seconds function delay { echo -e "${GREEN}Sleep for $1 seconds...${NC}"; sleep "$1"; } #Stop daemon if it's already running function stop_daemon { if pgrep -x 'esbcoind' > /dev/null; then echo -e "${YELLOW}Attempting to stop esbcoind${NC}" esbcoind-cli stop sleep 30 if pgrep -x 'esbcoind' > /dev/null; then echo -e "${RED}esbcoind daemon is still running!${NC} \a" echo -e "${RED}Attempting to kill...${NC}" pkill -9 esbcoind sleep 30 if pgrep -x 'esbcoind' > /dev/null; then echo -e "${RED}Can't stop esbcoind! Reboot and try again...${NC} \a" exit 2 fi fi fi } #Process command line parameters genkey=$1 clear echo -e "${GREEN} ------- ESBC MASTERNODE INSTALLER v2.1.0--------+ |+-----------------------------------------------+:| | |:: | The installation will install and run |:: | the masternode under a user ESBC. |:: | |:: | This version of installer will setup |:: | ufw for your safety. |:: | |:: +------------------------------------------------+:: ::::::::::::::::::::::::::::::::::::::::::::::::::S${NC}" echo "Do you want me to generate new masternode private key for you?[y/n]" read DOSETUP if [[ $DOSETUP =~ "n" ]] ; then read -e -p "Enter your private key:" genkey; read -e -p "Confirm your private key: " genkey2; fi #Confirming match if [ $genkey = $genkey2 ]; then echo -e "${GREEN}MATCH! ${NC} \a" else echo -e "${RED} Error: Private keys do not match. Try again or let me generate one for you...${NC} \a";exit 1 fi sleep .5 clear apt-get -qq install build-essential && apt-get -qq install libtool libevent-pthreads-2.0-5 autotools-dev autoconf automake && apt-get -qq install libssl-dev && apt-get -qq install libboost-all-dev && apt-get -qq install software-properties-common && add-apt-repository -y ppa:bitcoin/bitcoin && apt update && apt-get -qq install libdb4.8-dev && apt-get -qq install libdb4.8++-dev && apt-get -qq install libminiupnpc-dev && apt-get -qq install libqt4-dev libprotobuf-dev protobuf-compiler && apt-get -qq install libqrencode-dev && apt-get -qq install git && apt-get -qq install pkg-config && apt-get -qq install libzmq3-dev # Determine primary public IP address dpkg -s dnsutils 2>/dev/null >/dev/null || apt-get -y install dnsutils publicip=$(dig +short myip.opendns.com @resolver1.opendns.com) if [ -n "$publicip" ]; then echo -e "${YELLOW}IP Address detected:" $publicip ${NC} else echo -e "${RED}ERROR: Public IP Address was not detected!${NC} \a" clear_stdin read -e -p "Enter VPS Public IP Address: " publicip if [ -z "$publicip" ]; then echo -e "${RED}ERROR: Public IP Address must be provided. Try again...${NC} \a" exit 1 fi fi DEBIAN_FRONTEND=noninteractive apt-get update -y apt-get -y upgrade apt-get -y dist-upgrade apt-get -y autoremove apt-get -y install wget nano htop jq unzip fail2ban service fail2ban restart #Network Settings echo -e "${GREEN}Installing Network Settings...${NC}" { apt-get install ufw -y } &> /dev/null echo -ne '[## ] (10%)\r' { apt-get update -y } &> /dev/null echo -ne '[###### ] (30%)\r' { ufw default deny incoming } &> /dev/null echo -ne '[######### ] (50%)\r' { ufw default allow outgoing ufw allow ssh } &> /dev/null echo -ne '[########### ] (60%)\r' { ufw allow $PORT/tcp ufw allow $RPC/tcp } &> /dev/null echo -ne '[############### ] (80%)\r' { ufw allow 22/tcp ufw limit 22/tcp } &> /dev/null echo -ne '[################# ] (90%)\r' { echo -e "${YELLOW}" ufw --force enable echo -e "${NC}" } &> /dev/null echo -ne '[###################] (100%)\n' #Generating Random Password for JSON RPC rpcuser=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) rpcpassword=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) #Create 2GB swap file if grep -q "SwapTotal" /proc/meminfo; then echo -e "${GREEN}Skipping disk swap configuration...${NC} \n" else echo -e "${YELLOW}Creating 2GB disk swap file. \nThis may take a few minutes!${NC} \a" touch /var/swap.img chmod 600 swap.img dd if=/dev/zero of=/var/swap.img bs=1024k count=2000 mkswap /var/swap.img 2> /dev/null swapon /var/swap.img 2> /dev/null if [ $? -eq 0 ]; then echo '/var/swap.img none swap sw 0 0' >> /etc/fstab echo -e "${GREEN}Swap was created successfully!${NC} \n" else echo -e "${RED}Operation not permitted! Optional swap was not created.${NC} \a" rm /var/swap.img fi fi rm -rf .esbcoin/peers.dat .esbcoin/blocks .esbcoin/chainstate .esbcoin/database #Installing Daemon cd ~ rm -rf /usr/local/bin/esbcoin* rm -rf esbcoin-cli_ubuntu-16.04-x64.tar.bz2 rm -rf esbc-daemon-linux* wget -N https://github.com/BlockchainFor/ESBC2/releases/download/2.3.0.0/esbc-daemon-linux-x86_64-static.tar.gz tar -xvf esbc-daemon-linux-x86_64-static.tar.gz chmod -R 755 esbcoin-cli chmod -R 755 esbcoind cp -p -r esbcoind /usr/local/bin cp -p -r esbcoin-cli /usr/local/bin rm -rf esbcoin* rm -rf esbc-daemon-linux* esbcoin-cli stop #Create datadir if [ ! -f ~/.esbcoin/esbcoin.conf ]; then mkdir ~/.esbcoin fi clear echo -e "${YELLOW}Creating esbcoin.conf...${NC}" # If genkey was not supplied in command line, we will generate private key on the fly if [ -z $genkey ]; then cat < ~/.esbcoin/esbcoin.conf rpcuser=$rpcuser rpcpassword=$rpcpassword EOF chmod 755 -R ~/.esbcoin/esbcoin.conf #Starting daemon first time just to generate masternode private key esbcoind -daemon sleep 7 while true;do echo -e "${YELLOW}Generating masternode private key...${NC}" genkey=$(esbcoin-cli masternode genkey) if [ "$genkey" ]; then break fi sleep 7 done fi #Stopping daemon to create esbcoin.conf esbcoin-cli stop sleep .5 # Create esbcoin.conf cat < ~/.esbcoin/esbcoin.conf rpcuser=$rpcuser rpcpassword=$rpcpassword rpcallowip=127.0.0.1 rpcport=$RPC port=$PORT listen=1 server=1 daemon=1 logtimestamps=1 maxconnections=256 masternode=1 externalip=$publicip bind=$publicip masternodeaddr=$publicip masternodeprivkey=$genkey EOF #Bootstrap Installation echo "Do you want me to Download Bootstrap for fast Blockchain??[y/n]" read DOSETUP if [[ $DOSETUP =~ "n" ]] ; then echo -e "${GREEN}Bootstrap Installation is aborted... ${NC}" fi if [[ $DOSETUP =~ "y" ]] ; then echo -e "${GREEN}I will install bootstrap, will stop Server soon ... ${NC}" sleep 1s rm -rf .esbcoin/blocks .esbcoin/chainstate echo -e "${GREEN} Removing the current blockchain data... ${NC}" sleep 2s echo -e "${GREEN} I will start downloading the blockchain files in 5 seconds... ${NC}" sleep 5s wget https://files.esbc.pro/bootstrap.zip sleep 2s echo -e "${GREEN} Now i will install the actual blockchain data! ${NC}" sleep 1s sudo apt-get install unzip unzip -uq bootstrap.zip -d .esbcoin echo -e "${GREEN} Files succesfully installed! ${NC}" sleep 1s echo -e "${GREEN} Removing .zip file from your directory ${NC}" rm -rf bootstrap.zip echo -e "${GREEN} Starting the Server... ${NC}" sleep 1s else echo -e "${YELLOW}Bootstrap Installation was canceled... ${NC}" sleep 2 fi #Finally, starting daemon with new esbcoin.conf esbcoind -daemon sleep 5 #Setting auto start cron job for esbcoin printf '#!/bin/bash\nif [ ! -f "~/.esbcoin/esbcoin.pid" ]; then /usr/local/bin/esbcoind -daemon ; fi' > /root/esbcoin.sh chmod -R 755 esbcoin.sh #Setting auto start cron job for esbcoin if ! crontab -l | grep "esbcoin.sh"; then (crontab -l ; echo "*/5 * * * * /root/esbcoin.sh")| crontab - fi echo -e "======================================================================== ${GREEN}Masternode setup is complete!${NC} ======================================================================== Masternode was installed with VPS IP Address: ${GREEN}$publicip${NC} Masternode Private Key: ${GREEN}$genkey${NC} Now you can add the following string to the masternode.conf file ======================================================================== \a" echo -e "${GREEN}esbcoin_mn1 $publicip:$PORT $genkey TxId TxIdx${NC}" echo -e "======================================================================== Use your mouse to copy the whole string above into the clipboard by tripple-click + single-click (Dont use Ctrl-C) and then paste it into your ${GREEN}masternode.conf${NC} file and replace: ${GREEN}esbcoin_mn1${NC} - with your desired masternode name (alias) ${GREEN}TxId${NC} - with Transaction Id from masternode outputs ${GREEN}TxIdx${NC} - with Transaction Index (0 or 1) Remember to save the masternode.conf and restart the wallet! To introduce your new masternode to the esbcoin network, you need to issue a masternode start command from your wallet, which proves that the collateral for this node is secured." clear_stdin read -p "*** Press any key to continue ***" -n1 -s echo -e "Wait for the node wallet on this VPS to sync with the other nodes on the network. Eventually the 'Is Synced' status will change to 'true', which will indicate a comlete sync, although it may take from several minutes to several hours depending on the network state. Your initial Masternode Status may read: ${GREEN}Node just started, not yet activated${NC} or ${GREEN}Node is not in masternode list${NC}, which is normal and expected. " clear_stdin read -p "*** Press any key to continue ***" -n1 -s echo -e " ${GREEN}...scroll up to see previous screens...${NC} Here are some useful commands and tools for masternode troubleshooting: ======================================================================== To view masternode configuration produced by this script in esbcoin.conf: ${GREEN}cat ~/.esbcoin/esbcoin.conf${NC} Here is your esbcoin.conf generated by this script: -------------------------------------------------${GREEN}" echo -e "${GREEN}esbcoin_mn1 $publicip:$PORT $genkey TxId TxIdx${NC}" cat ~/.esbcoin/esbcoin.conf echo -e "${NC}------------------------------------------------- NOTE: To edit esbcoin.conf, first stop the esbcoind daemon, then edit the esbcoin.conf file and save it in nano: (Ctrl-X + Y + Enter), then start the esbcoind daemon back up: to stop: ${GREEN}esbcoin-cli stop${NC} to start: ${GREEN}esbcoind${NC} to edit: ${GREEN}nano ~/.esbcoin/esbcoin.conf${NC} to check mn status: ${GREEN}esbcoin-cli masternode status${NC} ======================================================================== To monitor system resource utilization and running processes: ${GREEN}htop${NC} ======================================================================== "