#!/bin/bash TMP_FOLDER=$(mktemp -d) CONFIG_FILE='Olympic.conf' CONFIGFOLDER='/root/.Olympic' COIN_DAEMON='/usr/local/bin/Olympicd' COIN_CLI='/usr/local/bin/Olympicd' COIN_REPO='https://github.com/OlympicCoinTeam/OlympicCoin/releases/download/v4.1.0.2/Olympicd' COIN_NAME='Olympic' COIN_BLOCK='https://github.com/OlympicCoinTeam/OlympicCoin/releases/download/v4.1.0.2/bootstrap.zip' COIN_PORT=26667 RPC_PORT=26666 NODEIP=$(curl -s4 api.ipify.org) RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' function compile_node() { echo -e "Prepare to download $COIN_NAME" cd $TMP_FOLDER wget -q $COIN_REPO chmod +x Olympicd cp Olympicd /usr/local/bin cd - rm -rf $TMP_FOLDER >/dev/null 2>&1 clear } function configure_systemd() { cat << EOF > /etc/systemd/system/$COIN_NAME.service [Unit] Description=$COIN_NAME service After=network.target [Service] User=root Group=root Type=forking #PIDFile=$CONFIGFOLDER/$COIN_NAME.pid ExecStart=$COIN_DAEMON -daemon -conf=$CONFIGFOLDER/$CONFIG_FILE -datadir=$CONFIGFOLDER ExecStop=-$COIN_CLI -conf=$CONFIGFOLDER/$CONFIG_FILE -datadir=$CONFIGFOLDER stop Restart=always PrivateTmp=true TimeoutStopSec=60s TimeoutStartSec=10s StartLimitInterval=120s StartLimitBurst=5 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload sleep 3 systemctl start $COIN_NAME.service systemctl enable $COIN_NAME.service >/dev/null 2>&1 } function create_config() { mkdir $CONFIGFOLDER >/dev/null 2>&1 RPCUSER=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w12 | head -n1) RPCPASSWORD=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w24 | head -n1) cat << EOF > $CONFIGFOLDER/$CONFIG_FILE rpcuser=$RPCUSER rpcpassword=$RPCPASSWORD rpcallowip=127.0.0.1 rpcport=$RPC_PORT listen=1 server=1 daemon=1 port=$COIN_PORT EOF } function download_blocks() { echo -e "Syncing ${RED}$COIN_NAME${NC} block chain, it might take a while and the screen will not move." cd $CONFIGFOLDER >/dev/null 2>&1 wget -q $COIN_BLOCK unzip -o bootstrap.zip >/dev/null 2>&1 rm bootstrap.zip >/dev/null 2>&1 cd - >/dev/null 2>&1 clear } function create_key() { echo -e "Enter your ${RED}$COIN_NAME Masternode Private Key${NC}. Leave it blank to generate a new ${RED}Masternode Private Key${NC} for you:" read -e COINKEY if [[ -z "$COINKEY" ]]; then $COIN_DAEMON -daemon sleep 30 if [ -z "$(ps axo cmd:100 | grep $COIN_DAEMON)" ]; then echo -e "${RED}$COIN_NAME server couldn not start. Check /var/log/syslog for errors.{$NC}" exit 1 fi COINKEY=$($COIN_CLI masternode genkey) if [ "$?" -gt "0" ]; then echo -e "${RED}Wallet not fully loaded. Let us wait and try again to generate the Private Key${NC}" sleep 30 COINKEY=$($COIN_CLI masternode genkey) fi $COIN_CLI stop fi clear } function update_config() { sed -i 's/daemon=1/daemon=0/' $CONFIGFOLDER/$CONFIG_FILE cat << EOF >> $CONFIGFOLDER/$CONFIG_FILE logintimestamps=1 maxconnections=256 masternode=1 #bind=$NODEIP masternodeaddr=$NODEIP:$COIN_PORT masternodeprivkey=$COINKEY EOF } function enable_firewall() { echo -e "Installing and setting up firewall to allow ingress on port ${GREEN}$COIN_PORT${NC}" ufw allow $COIN_PORT/tcp >/dev/null 2>&1 ufw allow $RPC_PORT/tcp >/dev/null 2>&1 ufw allow ssh comment "SSH" >/dev/null 2>&1 ufw limit ssh/tcp >/dev/null 2>&1 ufw default allow outgoing >/dev/null 2>&1 echo "y" | ufw enable >/dev/null 2>&1 } function get_ip() { declare -a NODE_IPS for ips in $(netstat -i | awk '!/Kernel|Iface|lo/ {print $1," "}') do NODE_IPS+=($(curl --interface $ips --connect-timeout 2 -s4 api.ipify.org)) done if [ ${#NODE_IPS[@]} -gt 1 ] then echo -e "${GREEN}More than one IP. Please type 0 to use the first IP, 1 for the second and so on...${NC}" INDEX=0 for ip in "${NODE_IPS[@]}" do echo ${INDEX} $ip let INDEX=${INDEX}+1 done read -e choose_ip NODEIP=${NODE_IPS[$choose_ip]} else NODEIP=${NODE_IPS[0]} fi } function compile_error() { if [ "$?" -gt "0" ]; then echo -e "${RED}Failed to compile $COIN_NAME. Please investigate.${NC}" exit 1 fi } function checks() { if [[ $(lsb_release -d) != *16.04* ]]; then echo -e "${RED}You are not running Ubuntu 14.04. Installation is cancelled.${NC}" exit 1 fi if [[ $EUID -ne 0 ]]; then echo -e "${RED}$0 must be run as root.${NC}" exit 1 fi if [ -n "$(pidof $COIN_DAEMON)" ] || [ -e "$COIN_DAEMOM" ] ; then echo -e "${RED}$COIN_NAME is already installed.${NC}" exit 1 fi } function prepare_system() { echo -e "Prepare the system to install ${GREEN}$COIN_NAME${NC} master node." apt-get update >/dev/null 2>&1 DEBIAN_FRONTEND=noninteractive apt-get update >/dev/null 2>&1 DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y -qq upgrade >/dev/null 2>&1 apt-get install -y software-properties-common >/dev/null 2>&1 echo -e "${GREEN}Adding bitcoin PPA repository" apt-add-repository -y ppa:bitcoin/bitcoin >/dev/null 2>&1 echo -e "Installing required packages, it may take some time to finish.${NC}" apt-get update >/dev/null 2>&1 apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" make software-properties-common \ build-essential libtool autoconf libssl-dev libboost-dev libboost-chrono-dev libboost-filesystem-dev libboost-program-options-dev \ libboost-system-dev libboost-test-dev libboost-thread-dev sudo automake git wget curl libdb4.8-dev bsdmainutils libdb4.8++-dev \ libminiupnpc-dev libgmp3-dev ufw pkg-config libevent-dev unzip >/dev/null 2>&1 if [ "$?" -gt "0" ]; then echo -e "${RED}Not all required packages were installed properly. Try to install them manually by running the following commands:${NC}\n" echo "apt-get update" echo "apt -y install software-properties-common" echo "apt-add-repository -y ppa:bitcoin/bitcoin" echo "apt-get update" echo "apt install -y make build-essential libtool software-properties-common autoconf libssl-dev libboost-dev libboost-chrono-dev libboost-filesystem-dev \ libboost-program-options-dev libboost-system-dev libboost-test-dev libboost-thread-dev sudo automake git pwgen curl libdb4.8-dev \ bsdmainutils libdb4.8++-dev libminiupnpc-dev libgmp3-dev ufw pkg-config libevent-dev unzip" exit 1 fi } function create_swap() { PHYMEM=$(free -g|awk '/^Mem:/{print $2}') SWAP=$(swapon -s) if [[ "$PHYMEM" -lt "2" && -z "$SWAP" ]]; then echo -e "${GREEN}Server is running with less than 2G of RAM, creating 2G swap file.${NC}" dd if=/dev/zero of=/swapfile bs=1024 count=2M chmod 600 /swapfile mkswap /swapfile swapon -a /swapfile else echo -e "${GREEN}The server running with at least 2G of RAM, or SWAP exists.${NC}" fi clear } function important_information() { echo echo -e "================================================================================================================================" echo -e "$COIN_NAME Masternode is up and running listening on port ${RED}$COIN_PORT${NC}." echo -e "Configuration file is: ${RED}$CONFIGFOLDER/$CONFIG_FILE${NC}" echo -e "Start: ${RED}systemctl start $COIN_NAME.service${NC}" echo -e "Stop: ${RED}systemctl stop $COIN_NAME.service${NC}" echo -e "VPS_IP:PORT ${RED}$NODEIP:$COIN_PORT${NC}" echo -e "MASTERNODE PRIVATEKEY is: ${RED}$COINKEY${NC}" echo -e "Please check ${RED}$COIN_NAME${NC} is running with the following command: ${RED}systemctl status $COIN_NAME.service${NC}" echo -e "================================================================================================================================" } function setup_node() { get_ip create_config download_blocks create_key update_config enable_firewall important_information configure_systemd } ##### Main ##### clear checks prepare_system create_swap compile_node setup_node