Advertisement
Guest User

Untitled

a guest
Apr 28th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.88 KB | None | 0 0
  1. #/bin/bash
  2. cd ~
  3. RED='\033[0;31m'
  4. GREEN='\033[0;32m'
  5. NC='\033[0m'
  6. IP4COUNT=$(find /root/.empirecoincwf_* -maxdepth 0 -type d | wc -l)
  7. DELETED="$(cat /root/bin/deletedempirecoin | wc -l)"
  8. ALIASES="$(find /root/.empirecoincwf_* -maxdepth 0 -type d | cut -c22-)"
  9. face="$(lshw -C network | grep "logical name:" | sed -e 's/logical name:/logical name: /g' | awk '{print $3}' | head -n1)"
  10. if [[ $EUID -ne 0 ]]; then
  11. echo -e "${RED}$0 must be run as root.${NC}"
  12. exit 1
  13. fi
  14. function configure_systemd() {
  15. cat << EOF > /etc/systemd/system/empirecoind$ALIAS.service
  16. [Unit]
  17. Description=empirecoind$ALIAS service
  18. After=network.target
  19. [Service]
  20. User=root
  21. Group=root
  22. Type=forking
  23. #PIDFile=/root/.empirecoincwf_$ALIAS/empirecoind.pid
  24. ExecStart=/root/bin/empirecoind_$ALIAS.sh
  25. ExecStop=/root/bin/empirecoin-cli_$ALIAS.sh stop
  26. Restart=always
  27. PrivateTmp=true
  28. TimeoutStopSec=60s
  29. TimeoutStartSec=10s
  30. StartLimitInterval=120s
  31. StartLimitBurst=5
  32. [Install]
  33. WantedBy=multi-user.target
  34. EOF
  35. systemctl daemon-reload
  36. sleep 6
  37. crontab -l > cron$ALIAS
  38. echo "@reboot systemctl start empirecoind$ALIAS" >> cron$ALIAS
  39. crontab cron$ALIAS
  40. rm cron$ALIAS
  41. systemctl start empirecoind$ALIAS.service
  42. }
  43. IP4=$(curl -s4 api.ipify.org)
  44. perl -i -ne 'print if ! $a{$_}++' /etc/network/interfaces
  45. if [ ! -f "/usr/local/bin/empirecoind" ]; then
  46. DOSETUP="y"
  47. else
  48. DOSETUP="n"
  49. fi
  50. clear
  51. echo "1 - Create new nodes"
  52. echo "2 - Remove an existing node"
  53. echo "3 - List aliases"
  54. echo "4 - Check for node errors"
  55. echo "What would you like to do?"
  56. read DO
  57. echo ""
  58.  
  59. if [ $DO = "4" ]
  60. then
  61. echo $ALIASES > temp1
  62. cat temp1 | grep -o '[^ |]*' > temp2
  63. CN="$(cat temp2 | wc -l)"
  64. rm temp1
  65. let LOOP=0
  66. while [ $LOOP -lt $CN ]; do
  67. LOOP=$((LOOP+1))
  68. CURRENT="$(sed -n "${LOOP}p" temp2)"
  69. echo -e "${GREEN}${CURRENT}${NC}:"
  70. sh /root/bin/empirecoin-cli_${CURRENT}.sh masternode status | grep "message"
  71. OFFSET="$(sh /root/bin/empirecoin-cli_${CURRENT}.sh getinfo | grep "timeoffset")"
  72. OFF1=${OFFSET:(-2)}
  73. OFF=${OFF1:0:1}
  74. if [ $OFF = "1" ]
  75. then
  76. echo "$OFFSET"
  77. fi
  78. done
  79. rm temp2
  80. fi
  81. if [ $DO = "3" ]
  82. then
  83. echo -e "${GREEN}${ALIASES}${NC}"
  84. echo ""
  85. echo "1 - Create new nodes"
  86. echo "2 - Remove an existing node"
  87. echo "What would you like to do?"
  88. read DO
  89. echo ""
  90. fi
  91. if [ $DO = "2" ]
  92. then
  93. perl -i -ne 'print if ! $a{$_}++' /etc/monit/monitrc >/dev/null 2>&1
  94. echo "Input the alias of the node that you want to delete"
  95. read ALIASD
  96. echo ""
  97. echo -e "${GREEN}Deleting ${ALIASD}${NC}. Please wait."
  98. ## Removing service
  99. systemctl stop empirecoind$ALIASD >/dev/null 2>&1
  100. systemctl disable empirecoind$ALIASD >/dev/null 2>&1
  101. rm /etc/systemd/system/empirecoind${ALIASD}.service >/dev/null 2>&1
  102. systemctl daemon-reload >/dev/null 2>&1
  103. systemctl reset-failed >/dev/null 2>&1
  104. rm /root/.empirecoincwf_$ALIASD -r >/dev/null 2>&1
  105. sed -i "/${ALIASD}/d" .bashrc
  106. crontab -l -u root | grep -v empirecoind$ALIASD | crontab -u root - >/dev/null 2>&1
  107. source .bashrc
  108. echo "1" >> /root/bin/deletedempirecoin
  109. echo -e "${ALIASD} Successfully deleted."
  110. fi
  111. if [ $DO = "1" ]
  112. then
  113. echo "1 - Easy mode"
  114. echo "2 - Expert mode"
  115. echo "Please select a option:"
  116. read EE
  117. echo ""
  118. if [ $EE = "1" ]
  119. then
  120. MAXC="64"
  121. fi
  122. if [ $EE = "2" ]
  123. then
  124. echo ""
  125. echo "Enter max connections value"
  126. read MAXC
  127. fi
  128. if [ $DOSETUP = "y" ]
  129. then
  130.  
  131. ## Installing pre-requisites
  132.  
  133. echo -e "Installing ${GREEN}Empire Coin dependencies${NC}. Please wait."
  134. apt-get update
  135. apt-get -y upgrade
  136. apt install software-properties-common -y
  137. add-apt-repository universe -y
  138. apt update
  139. apt install -y zip unzip bc curl nano lshw ufw gawk libdb++-dev git zip automake software-properties-common unzip build-essential libtool autotools-dev autoconf pkg-config libssl-dev libcrypto++-dev libevent-dev libminiupnpc-dev libgmp-dev libboost-all-dev devscripts libsodium-dev libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler libcrypto++-dev libminiupnpc-dev qt5-default gcc-5 g++-5 --auto-remove
  140. thr="$(nproc)"
  141.  
  142. ## Creating swap
  143.  
  144. echo -e "${RED}Creating swap. This may take a while.${NC}"
  145. dd if=/dev/zero of=/var/swap.img bs=2048 count=1M
  146. chmod 600 /var/swap.img
  147. mkswap /var/swap.img
  148. swapon /var/swap.img
  149. free -m
  150. echo "/var/swap.img none swap sw 0 0" >> /etc/fstab
  151.  
  152. ## Compatibility issues
  153.  
  154. export LC_CTYPE=en_US.UTF-8
  155. export LC_ALL=en_US.UTF-8
  156. apt update
  157. apt install libssl1.0-dev -y
  158. apt install libzmq3-dev -y --auto-remove
  159. update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 100
  160. update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 100
  161.  
  162. ## Preparing and building
  163.  
  164. git clone https://github.com/EmpireCryptoNetwork/emp.git
  165. cd emp
  166. chmod +x */*/*
  167. ./autogen.sh
  168. ./configure --with-incompatible-bdb --disable-tests --without-gui
  169. make -j $thr
  170. make install
  171.  
  172. ## Final configs
  173.  
  174. ufw allow ssh/tcp
  175. ufw limit ssh/tcp
  176. ufw logging on
  177. echo "y" | ufw enable
  178. ufw allow 14321
  179. echo 'export PATH=~/bin:$PATH' > ~/.bash_aliases
  180. source ~/.bashrc
  181. echo ""
  182. cd
  183. sysctl vm.swappiness=10
  184. sysctl vm.vfs_cache_pressure=200
  185. echo 'vm.swappiness=10' | tee -a /etc/sysctl.conf
  186. echo 'vm.vfs_cache_pressure=200' | tee -a /etc/sysctl.conf
  187. fi
  188. gateway1=$(/sbin/route -A inet6 | grep -v ^fe80 | grep -v ^ff00 | grep -w "$face")
  189. gateway2=${gateway1:0:26}
  190. gateway3="$(echo -e "${gateway2}" | tr -d '[:space:]')"
  191. if [[ $gateway3 = *"128"* ]]; then
  192. gateway=${gateway3::-5}
  193. fi
  194. if [[ $gateway3 = *"64"* ]]; then
  195. gateway=${gateway3::-3}
  196. fi
  197. MASK="/64"
  198. echo -e "empirecoin nodes currently installed: ${GREEN}${IP4COUNT}${NC}, empirecoin nodes previously Deleted: ${GREEN}${DELETED}${NC}"
  199. echo ""
  200. if [ $IP4COUNT = "0" ]
  201. then
  202. echo -e "${RED}First node must be ipv4.${NC}"
  203. let COUNTER=0
  204. PORT=14321
  205. RPCPORTT=143210
  206. RPCPORT=$(($RPCPORTT+$COUNTER))
  207. echo ""
  208. echo "Enter alias for first node"
  209. read ALIAS
  210. CONF_DIR=~/.empirecoincwf_$ALIAS
  211. echo ""
  212. echo "Enter masternode private key for node $ALIAS"
  213. read PRIVKEY
  214. mkdir ~/.empirecoincwf_$ALIAS
  215. echo '#!/bin/bash' > ~/bin/empirecoind_$ALIAS.sh
  216. echo "empirecoind -daemon -conf=$CONF_DIR/empirecoin.conf -datadir=$CONF_DIR "'$*' >> ~/bin/empirecoind_$ALIAS.sh
  217. echo '#!/bin/bash' > ~/bin/empirecoin-cli_$ALIAS.sh
  218. echo "empirecoin-cli -conf=$CONF_DIR/empirecoin.conf -datadir=$CONF_DIR "'$*' >> ~/bin/empirecoin-cli_$ALIAS.sh
  219. chmod 755 ~/bin/empirecoin*.sh
  220. mkdir -p $CONF_DIR
  221. echo "rpcuser=user"`shuf -i 100000-10000000 -n 1` >> empirecoin.conf_TEMP
  222. echo "rpcpassword=pass"`shuf -i 100000-10000000 -n 1` >> empirecoin.conf_TEMP
  223. echo "rpcallowip=127.0.0.1" >> empirecoin.conf_TEMP
  224. echo "rpcport=$RPCPORT" >> empirecoin.conf_TEMP
  225. echo "listen=1" >> empirecoin.conf_TEMP
  226. echo "server=1" >> empirecoin.conf_TEMP
  227. echo "daemon=1" >> empirecoin.conf_TEMP
  228. echo "logtimestamps=1" >> empirecoin.conf_TEMP
  229. echo "maxconnections=$MAXC" >> empirecoin.conf_TEMP
  230. echo "masternode=1" >> empirecoin.conf_TEMP
  231. echo "dbcache=20" >> empirecoin.conf_TEMP
  232. echo "maxorphantx=5" >> empirecoin.conf_TEMP
  233. echo "maxmempool=100" >> empirecoin.conf_TEMP
  234. echo "" >> empirecoin.conf_TEMP
  235. echo "" >> empirecoin.conf_TEMP
  236. echo "bind=$IP4:$PORT" >> empirecoin.conf_TEMP
  237. echo "externalip=$IP4" >> empirecoin.conf_TEMP
  238. echo "masternodeaddr=$IP4:$PORT" >> empirecoin.conf_TEMP
  239. echo "masternodeprivkey=$PRIVKEY" >> empirecoin.conf_TEMP
  240.  
  241.  
  242. mv empirecoin.conf_TEMP $CONF_DIR/empirecoin.conf
  243. echo ""
  244. echo -e "Your ip is ${GREEN}$IP4:$PORT${NC}"
  245. echo "alias ${ALIAS}_status=\"empirecoin-cli -datadir=/root/.empirecoincwf_${ALIAS} masternode status\"" >> .bashrc
  246. echo "alias ${ALIAS}_stop=\"systemctl stop empirecoind$ALIAS\"" >> .bashrc
  247. echo "alias ${ALIAS}_start=\"systemctl start empirecoind$ALIAS\"" >> .bashrc
  248. echo "alias ${ALIAS}_config=\"nano /root/.empirecoincwf_${ALIAS}/empirecoin.conf\"" >> .bashrc
  249. echo "alias ${ALIAS}_getinfo=\"empirecoin-cli -datadir=/root/'.empirecoincwf_${ALIAS} getinfo\"" >> .bashrc
  250. echo "alias ${ALIAS}_getpeerinfo=\"empirecoin-cli -datadir=/root/.empirecoincwf_${ALIAS} getpeerinfo\"" >> .bashrc
  251. echo "alias ${ALIAS}_resync=\"/root/bin/empirecoind_${ALIAS}.sh -resync\"" >> .bashrc
  252. echo "alias ${ALIAS}_reindex=\"/root/bin/empirecoind_${ALIAS}.sh -reindex\"" >> .bashrc
  253. echo "alias ${ALIAS}_restart=\"systemctl restart empirecoind$ALIAS\"" >> .bashrc
  254. ## Config Systemctl
  255. configure_systemd
  256. fi
  257. if [ $IP4COUNT != "0" ]
  258. then
  259. echo "How many ipv6 nodes do you want to install on this server?"
  260. read MNCOUNT
  261. let MNCOUNT=MNCOUNT+1
  262. let MNCOUNT=MNCOUNT+IP4COUNT
  263. let MNCOUNT=MNCOUNT+DELETED
  264. let COUNTER=1
  265. let COUNTER=COUNTER+IP4COUNT
  266. let COUNTER=COUNTER+DELETED
  267. while [ $COUNTER -lt $MNCOUNT ]; do
  268. PORT=14321
  269. RPCPORTT=143210
  270. RPCPORT=$(($RPCPORTT+$COUNTER))
  271. echo ""
  272. echo "Enter alias for new node"
  273. read ALIAS
  274. CONF_DIR=~/.empirecoincwf_$ALIAS
  275. echo ""
  276. echo "Enter masternode private key for node $ALIAS"
  277. read PRIVKEY
  278. echo "up /sbin/ip -6 addr add ${gateway}$COUNTER$MASK dev $face # $ALIAS" >> /etc/network/interfaces
  279. /sbin/ip -6 addr add ${gateway}$COUNTER$MASK dev $face
  280. mkdir ~/.empirecoincwf_$ALIAS
  281. unzip Bootstrap.zip -d ~/.empirecoincwf_$ALIAS >/dev/null 2>&1
  282. echo '#!/bin/bash' > ~/bin/empirecoind_$ALIAS.sh
  283. echo "empirecoind -daemon -conf=$CONF_DIR/empirecoin.conf -datadir=$CONF_DIR "'$*' >> ~/bin/empirecoind_$ALIAS.sh
  284. echo '#!/bin/bash' > ~/bin/empirecoin-cli_$ALIAS.sh
  285. echo "empirecoin-cli -conf=$CONF_DIR/empirecoin.conf -datadir=$CONF_DIR "'$*' >> ~/bin/empirecoin-cli_$ALIAS.sh
  286. chmod 755 ~/bin/empirecoin*.sh
  287. mkdir -p $CONF_DIR
  288. echo "rpcuser=user"`shuf -i 100000-10000000 -n 1` >> empirecoin.conf_TEMP
  289. echo "rpcpassword=pass"`shuf -i 100000-10000000 -n 1` >> empirecoin.conf_TEMP
  290. echo "rpcallowip=127.0.0.1" >> empirecoin.conf_TEMP
  291. echo "rpcport=$RPCPORT" >> empirecoin.conf_TEMP
  292. echo "listen=1" >> empirecoin.conf_TEMP
  293. echo "server=1" >> empirecoin.conf_TEMP
  294. echo "daemon=1" >> empirecoin.conf_TEMP
  295. echo "logtimestamps=1" >> empirecoin.conf_TEMP
  296. echo "maxconnections=$MAXC" >> empirecoin.conf_TEMP
  297. echo "masternode=1" >> empirecoin.conf_TEMP
  298. echo "dbcache=20" >> empirecoin.conf_TEMP
  299. echo "maxorphantx=5" >> empirecoin.conf_TEMP
  300. echo "maxmempool=100" >> empirecoin.conf_TEMP
  301. echo "bind=[${gateway}$COUNTER]:$PORT" >> empirecoin.conf_TEMP
  302. echo "externalip=[${gateway}$COUNTER]" >> empirecoin.conf_TEMP
  303. echo "masternodeaddr=[${gateway}$COUNTER]:$PORT" >> empirecoin.conf_TEMP
  304. echo "masternodeprivkey=$PRIVKEY" >> empirecoin.conf_TEMP
  305. mv empirecoin.conf_TEMP $CONF_DIR/empirecoin.conf
  306. echo ""
  307. echo -e "Your ip is ${GREEN}[${gateway}$COUNTER]:$PORT${NC}"
  308. echo "alias ${ALIAS}_status=\"empirecoin-cli -datadir=/root/.empirecoincwf_${ALIAS} masternode status\"" >> .bashrc
  309. echo "alias ${ALIAS}_stop=\"systemctl stop empirecoind$ALIAS\"" >> .bashrc
  310. echo "alias ${ALIAS}_start=\"systemctl start empirecoind$ALIAS\"" >> .bashrc
  311. echo "alias ${ALIAS}_config=\"nano /root/.empirecoincwf_${ALIAS}/empirecoin.conf\"" >> .bashrc
  312. echo "alias ${ALIAS}_getinfo=\"empirecoin-cli -datadir=/root/.empirecoincwf_${ALIAS} getinfo\"" >> .bashrc
  313. echo "alias ${ALIAS}_getpeerinfo=\"empirecoin-cli -datadir=/root/.empirecoincwf_${ALIAS} getpeerinfo\"" >> .bashrc
  314. echo "alias ${ALIAS}_resync=\"/root/bin/empirecoind_${ALIAS}.sh -resync\"" >> .bashrc
  315. echo "alias ${ALIAS}_reindex=\"/root/bin/empirecoind_${ALIAS}.sh -reindex\"" >> .bashrc
  316. echo "alias ${ALIAS}_restart=\"systemctl restart empirecoind$ALIAS\"" >> .bashrc
  317. ## Config Systemctl
  318. configure_systemd
  319. COUNTER=$((COUNTER+1))
  320. done
  321. fi
  322. echo ""
  323. echo "Commands:"
  324. echo "${ALIAS}_start"
  325. echo "${ALIAS}_restart"
  326. echo "${ALIAS}_status"
  327. echo "${ALIAS}_stop"
  328. echo "${ALIAS}_config"
  329. echo "${ALIAS}_getinfo"
  330. echo "${ALIAS}_getpeerinfo"
  331. echo "${ALIAS}_resync"
  332. echo "${ALIAS}_reindex"
  333. fi
  334. echo ""
  335. echo "Made by lobo"
  336. echo "Bitcoin Address for donations: 1NqYjVMA5DhuLytt33HYgP5qBajeHLYn4d"
  337. exec bash
  338. exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement