Advertisement
Guest User

Untitled

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