Advertisement
Guest User

Adrmn.sh

a guest
Apr 27th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 9.01 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. TMP_FOLDER=$(mktemp -d)
  4. CONFIG_FILE='adirondack.conf'
  5. CONFIGFOLDER='/root/.adirondack'
  6. COIN_DAEMON='adirondackd'
  7. COIN_CLI='adirondack-cli'
  8. COIN_PATH='/usr/local/bin/'
  9. COIN_REPO='https://github.com/adirondackcoin/Adirondack.git'
  10. COIN_TGZ=''
  11. COIN_ZIP=$(echo $COIN_TGZ | awk -F'/' '{print $NF}')
  12. COIN_NAME='Adirondack'
  13. COIN_PORT=22119
  14. RPC_PORT=22120
  15.  
  16. NODEIP=45.76.35.36
  17.  
  18.  
  19. RED='\033[0;31m'
  20. GREEN='\033[0;32m'
  21. NC='\033[0m'
  22.  
  23.  
  24. function compile_node() {
  25.   echo -e "Prepare to compile $COIN_NAME"
  26.   git clone $COIN_REPO $TMP_FOLDER >/dev/null 2>&1
  27.   compile_error
  28.   cd $TMP_FOLDER
  29.   chmod +x ./autogen.sh
  30.   chmod +x ./share/genbuild.sh
  31.   chmod +x ./src/leveldb/build_detect_platform
  32.   ./autogen.sh
  33.   compile_error
  34.   ./configure
  35.   compile_error
  36.   make
  37.   compile_error
  38.   make install
  39.   compile_error
  40.   strip $COIN_PATH$COIN_DAEMON $COIN_PATH$COIN_CLI
  41.   cd - >/dev/null 2>&1
  42.   rm -rf $TMP_FOLDER >/dev/null 2>&1
  43.   clear
  44. }
  45.  
  46. function download_node() {
  47.   echo -e "Prepare to download $COIN_NAME binaries"
  48.   cd $TMP_FOLDER
  49.   wget -q $COIN_TGZ
  50.   tar xvzf $COIN_ZIP -C /usr/local/bin/
  51.   compile_error
  52.   chmod +x $COIN_PATH$COIN_DAEMON $COIN_PATH$COIN_CLI
  53.   cd - >/dev/null 2>&1
  54.   rm -r $TMP_FOLDER >/dev/null 2>&1
  55.   clear
  56. }
  57.  
  58. function ask_permission() {
  59.  echo -e "${RED}I trust zoldur and want to use$ $COIN_NAME binaries compiled on his server.${NC}."
  60.  echo -e "Please type ${RED}YES${NC} if you want to use precompiled binaries, or type anything else to compile them on your server"
  61.  read -e ZOLDUR
  62. }
  63.  
  64. function configure_systemd() {
  65.   cat << EOF > /etc/systemd/system/$COIN_NAME.service
  66. [Unit]
  67. Description=$COIN_NAME service
  68. After=network.target
  69. [Service]
  70. User=root
  71. Group=root
  72. Type=forking
  73. #PIDFile=$CONFIGFOLDER/$COIN_NAME.pid
  74. ExecStart=$COIN_PATH$COIN_DAEMON -daemon -conf=$CONFIGFOLDER/$CONFIG_FILE -datadir=$CONFIGFOLDER
  75. ExecStop=-$COIN_PATH$COIN_CLI -conf=$CONFIGFOLDER/$CONFIG_FILE -datadir=$CONFIGFOLDER stop
  76. Restart=always
  77. PrivateTmp=true
  78. TimeoutStopSec=60s
  79. TimeoutStartSec=10s
  80. StartLimitInterval=120s
  81. StartLimitBurst=5
  82. [Install]
  83. WantedBy=multi-user.target
  84. EOF
  85.  
  86.   systemctl daemon-reload
  87.   sleep 3
  88.   systemctl start $COIN_NAME.service
  89.   systemctl enable $COIN_NAME.service >/dev/null 2>&1
  90.  
  91.   if [[ -z "$(ps axo cmd:100 | egrep $COIN_DAEMON)" ]]; then
  92.     echo -e "${RED}$COIN_NAME is not running${NC}, please investigate. You should start by running the following commands as root:"
  93.     echo -e "${GREEN}systemctl start $COIN_NAME.service"
  94.     echo -e "systemctl status $COIN_NAME.service"
  95.     echo -e "less /var/log/syslog${NC}"
  96.     exit 1
  97.   fi
  98. }
  99.  
  100.  
  101. function create_config() {
  102.   mkdir $CONFIGFOLDER >/dev/null 2>&1
  103.   RPCUSER=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w10 | head -n1)
  104.   RPCPASSWORD=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w22 | head -n1)
  105.   cat << EOF > $CONFIGFOLDER/$CONFIG_FILE
  106. rpcuser=$RPCUSER
  107. rpcpassword=$RPCPASSWORD
  108. rpcallowip=127.0.0.1
  109. listen=1
  110. server=1
  111. daemon=1
  112. port=$COIN_PORT
  113. EOF
  114. }
  115.  
  116. function create_key() {
  117.   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:"
  118.   read -e COINKEY
  119.   if [[ -z "$COINKEY" ]]; then
  120.   $COIN_PATH$COIN_DAEMON -daemon
  121.   sleep 30
  122.   if [ -z "$(ps axo cmd:100 | grep $COIN_DAEMON)" ]; then
  123.    echo -e "${RED}$COIN_NAME server couldn not start. Check /var/log/syslog for errors.{$NC}"
  124.    exit 1
  125.   fi
  126.   COINKEY=$($COIN_PATH$COIN_CLI masternode genkey)
  127.   if [ "$?" -gt "0" ];
  128.     then
  129.     echo -e "${RED}Wallet not fully loaded. Let us wait and try again to generate the Private Key${NC}"
  130.     sleep 30
  131.     COINKEY=$($COIN_PATH$COIN_CLI masternode genkey)
  132.   fi
  133.   $COIN_PATH$COIN_CLI stop
  134. fi
  135. clear
  136. }
  137.  
  138. function update_config() {
  139.   sed -i 's/daemon=1/daemon=0/' $CONFIGFOLDER/$CONFIG_FILE
  140.   cat << EOF >> $CONFIGFOLDER/$CONFIG_FILE
  141. logintimestamps=1
  142. maxconnections=256
  143. #bind=$NODEIP
  144. masternode=1
  145. externalip=$NODEIP:$COIN_PORT
  146. masternodeprivkey=$COINKEY
  147. EOF
  148. }
  149.  
  150.  
  151. function enable_firewall() {
  152.   echo -e "Installing and setting up firewall to allow ingress on port ${GREEN}$COIN_PORT${NC}"
  153.   ufw allow $COIN_PORT/tcp comment "$COIN_NAME MN port" >/dev/null
  154.   ufw allow ssh comment "SSH" >/dev/null 2>&1
  155.   ufw limit ssh/tcp >/dev/null 2>&1
  156.   ufw default allow outgoing >/dev/null 2>&1
  157.   echo "y" | ufw enable >/dev/null 2>&1
  158. }
  159.  
  160.  
  161.  
  162. function get_ip() {
  163.   declare -a NODE_IPS
  164.   for ips in $(netstat -i | awk '!/Kernel|Iface|lo/ {print $1," "}')
  165.   do
  166.     NODE_IPS+=($(curl --interface $ips --connect-timeout 2 -s4 icanhazip.com))
  167.   done
  168.  
  169.   if [ ${#NODE_IPS[@]} -gt 1 ]
  170.     then
  171.       echo -e "${GREEN}More than one IP. Please type 0 to use the first IP, 1 for the second and so on...${NC}"
  172.       INDEX=0
  173.       for ip in "${NODE_IPS[@]}"
  174.       do
  175.         echo ${INDEX} $ip
  176.         let INDEX=${INDEX}+1
  177.       done
  178.       read -e choose_ip
  179.       NODEIP=${NODE_IPS[$choose_ip]}
  180.   else
  181.     NODEIP=${NODE_IPS[0]}
  182.   fi
  183. }
  184.  
  185.  
  186. function compile_error() {
  187. if [ "$?" -gt "0" ];
  188.  then
  189.   echo -e "${RED}Failed to compile $COIN_NAME. Please investigate.${NC}"
  190.   exit 1
  191. fi
  192. }
  193.  
  194.  
  195. function checks() {
  196. if [[ $(lsb_release -d) != *16.04* ]]; then
  197.   echo -e "${RED}You are not running Ubuntu 16.04. Installation is cancelled.${NC}"
  198.   exit 1
  199. fi
  200.  
  201. if [[ $EUID -ne 0 ]]; then
  202.    echo -e "${RED}$0 must be run as root.${NC}"
  203.    exit 1
  204. fi
  205.  
  206. if [ -n "$(pidof $COIN_DAEMON)" ] || [ -e "$COIN_DAEMOM" ] ; then
  207.   echo -e "${RED}$COIN_NAME is already installed.${NC}"
  208.   exit 1
  209. fi
  210. }
  211.  
  212. function prepare_system() {
  213. echo -e "Prepare the system to install ${GREEN}$COIN_NAME${NC} master node."
  214. apt-get update >/dev/null 2>&1
  215. DEBIAN_FRONTEND=noninteractive apt-get update > /dev/null 2>&1
  216. DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y -qq upgrade >/dev/null 2>&1
  217. apt install -y software-properties-common >/dev/null 2>&1
  218. echo -e "${GREEN}Adding bitcoin PPA repository"
  219. apt-add-repository -y ppa:bitcoin/bitcoin >/dev/null 2>&1
  220. echo -e "Installing required packages, it may take some time to finish.${NC}"
  221. apt-get update >/dev/null 2>&1
  222. apt-get install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" make software-properties-common \
  223. build-essential libtool autoconf libssl-dev libboost-dev libboost-chrono-dev libboost-filesystem-dev libboost-program-options-dev \
  224. libboost-system-dev libboost-test-dev libboost-thread-dev sudo automake git wget curl libdb4.8-dev bsdmainutils libdb4.8++-dev \
  225. libminiupnpc-dev libgmp3-dev ufw pkg-config libevent-dev  libdb5.3++ libzmq5 >/dev/null 2>&1
  226. if [ "$?" -gt "0" ];
  227.   then
  228.     echo -e "${RED}Not all required packages were installed properly. Try to install them manually by running the following commands:${NC}\n"
  229.     echo "apt-get update"
  230.     echo "apt -y install software-properties-common"
  231.     echo "apt-add-repository -y ppa:bitcoin/bitcoin"
  232.     echo "apt-get update"
  233.     echo "apt install -y make build-essential libtool software-properties-common autoconf libssl-dev libboost-dev libboost-chrono-dev libboost-filesystem-dev \
  234. libboost-program-options-dev libboost-system-dev libboost-test-dev libboost-thread-dev sudo automake git curl libdb4.8-dev \
  235. bsdmainutils libdb4.8++-dev libminiupnpc-dev libgmp3-dev ufw fail2ban pkg-config libevent-dev libzmq5"
  236.  exit 1
  237. fi
  238.  
  239. clear
  240. }
  241.  
  242. function create_swap() {
  243.  echo -e "Checking if swap space is needed."
  244.  PHYMEM=$(free -g|awk '/^Mem:/{print $2}')
  245.  SWAP=$(free -g|awk '/^Swap:/{print $2}')
  246.  if [ "$PHYMEM" -lt "2" ] && [ -n "$SWAP" ]
  247.   then
  248.     echo -e "${GREEN}Server is running with less than 2G of RAM without SWAP, creating 2G swap file.${NC}"
  249.     SWAPFILE=$(mktemp)
  250.     dd if=/dev/zero of=$SWAPFILE bs=1024 count=2M
  251.     chmod 600 $SWAPFILE
  252.     mkswap $SWAPFILE
  253.     swapon -a $SWAPFILE
  254.  else
  255.   echo -e "${GREEN}Server running with at least 2G of RAM, no swap needed.${NC}"
  256.  fi
  257.  clear
  258. }
  259.  
  260.  
  261. function important_information() {
  262.  echo
  263.  echo -e "================================================================================================================================"
  264.  echo -e "$COIN_NAME Masternode is up and running listening on port ${RED}$COIN_PORT${NC}."
  265.  echo -e "Configuration file is: ${RED}$CONFIGFOLDER/$CONFIG_FILE${NC}"
  266.  echo -e "Start: ${RED}systemctl start $COIN_NAME.service${NC}"
  267.  echo -e "Stop: ${RED}systemctl stop $COIN_NAME.service${NC}"
  268.  echo -e "VPS_IP:PORT ${RED}$NODEIP:$COIN_PORT${NC}"
  269.  echo -e "MASTERNODE PRIVATEKEY is: ${RED}$COINKEY${NC}"
  270.  echo -e "Please check ${RED}$COIN_NAME${NC} is running with the following command: ${RED}systemctl status $COIN_NAME.service${NC}"
  271.  echo -e "================================================================================================================================"
  272. }
  273.  
  274. function setup_node() {
  275.   get_ip
  276.   create_config
  277.   create_key
  278.   update_config
  279.   enable_firewall
  280.   important_information
  281.   configure_systemd
  282. }
  283.  
  284.  
  285. ##### Main #####
  286. clear
  287.  
  288. checks
  289. prepare_system
  290. #ask_permission
  291. #if [[ "$ZOLDUR" == "YES" ]]; then
  292. #  download_node
  293. #else
  294.   create_swap
  295.   compile_node
  296. #fi
  297. setup_node
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement