Advertisement
Guest User

Untitled

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