Advertisement
BaalMcKloud

Howto install a Bitcoin Node with Monitoring

Feb 28th, 2016
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Automated Ubuntu instance setup script
  4. # To take a clean Ubuntu 12.04 LTS install to a fully running
  5. # and secure Bitcoin node.
  6.  
  7. # [TODO] Check that we are running as root, sudo'd or otherwise
  8.  
  9. # Setup the and update the packages
  10.  
  11. apt-get update -y
  12. apt-get upgrade -y
  13. apt-get install git -y
  14. apt-get install software-properties-common python-software-properties -y
  15. apt-get install vnstat -y
  16. apt-get install apache2 php5 php5-gd -y
  17. #apt-get install ufw -y
  18. apt-get install fail2ban -y
  19.  
  20. # the following line must come after "python-software-properties"
  21. add-apt-repository -y ppa:bitcoin/bitcoin
  22. apt-get update -y
  23. apt-get upgrade -y
  24. apt-get install bitcoind -y
  25.  
  26. # Setup a swap device
  27. # [TODO] Check if the swap is already enabled
  28. #dd if=/dev/zero of=/swapfile bs=1M count=1024 ; mkswap /swapfile ; swapon /swapfile
  29. #echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
  30.  
  31. # Setup the firewall
  32. #ufw allow 22/tcp
  33. #ufw allow 80/tcp
  34. #ufw allow 8333/tcp
  35. #ufw --force enable
  36.  
  37. # Setup bitcoinrpc
  38. git clone https://github.com/jgarzik/python-bitcoinrpc
  39. pushd python-bitcoinrpc
  40. python setup.py build
  41. python setup.py install
  42. popd
  43. rm -rf python-bitcoinrpc
  44.  
  45. #Setup vnstat
  46. device_test=`ifconfig | grep eth0`
  47. net_device=""
  48. if [ "$device_test" = "" ]; then
  49.     echo "Found venet0 device"
  50.     net_device="venet0"
  51. else
  52.     echo "Found eth0 device"
  53.     net_device="eth0"
  54. fi
  55. vnstat -u -i $net_device
  56. vnstat -i $net_device
  57. /etc/init.d/apache2 start
  58. pushd /tmp
  59. wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz
  60. tar xvf vnstat_php_frontend-1.5.1.tar.gz
  61. sed -i "s/\$language = 'nl'/\$language = 'en'/" vnstat_php_frontend-1.5.1/config.php
  62. if [ "$net_device" = "venet0" ]; then
  63.     sed -i "s/eth0/venet0/" vnstat_php_frontend-1.5.1/config.php
  64. fi
  65. cp -fr vnstat_php_frontend-1.5.1/ /var/www/vnstat
  66. popd
  67.  
  68. ### FINISHED root level setup, now proceeding to the service user.
  69. # [TODO] Run this as the service user
  70.  
  71. # Setup bitcoin
  72. if [ ! -d ".bitcoin" ]; then
  73.     mkdir .bitcoin
  74. fi
  75. config=".bitcoin/bitcoin.conf"
  76. touch $config
  77. echo "server=1" > $config
  78. echo "daemon=1" >> $config
  79. echo "connections=100" >> $config
  80. randUser=`< /dev/urandom tr -dc A-Za-z0-9 | head -c30`
  81. randPass=`< /dev/urandom tr -dc A-Za-z0-9 | head -c30`
  82. echo "rpcuser=$randUser" >> $config
  83. echo "rpcpassword=$randPass" >> $config
  84. bitcoind -daemon
  85.  
  86. crontab -l > tempcron
  87. echo "@reboot bitcoind -daemon" >> tempcron
  88. echo "*/5 * * * * python /usr/local/bin/btc-update.py" >> tempcron
  89. echo "*/5 * * * * /usr/bin/vnstat -u >/dev/null 2>&1" >> tempcron
  90. crontab tempcron
  91. rm tempcron
  92.  
  93. scriptFilename="/usr/local/bin/btc-update.py"
  94. cat <<EOM > $scriptFilename
  95. #!/usr/bin/python
  96. from bitcoinrpc.authproxy import AuthServiceProxy
  97. import time
  98.  
  99. access = AuthServiceProxy("http://RPCUSER:RPCPASSWORD@127.0.0.1:8332")
  100. info = access.getinfo()
  101.  
  102. ff = open('/var/www/index.html', 'w')
  103.  
  104.  
  105. ff.write("<!DOCTYPE html>")
  106. ff.write("<html lang='en-us'>")
  107. ff.write("<head>")
  108. ff.write("<meta charset='utf-8'>")
  109. ff.write("<title>Bitcoin Node Status</title>")
  110. ff.write("<link href='http://fonts.googleapis.com/css?family=Exo+2:300,400' rel='stylesheet' type='text/css'>")
  111. ff.write("<style type='text/css'> ")
  112. ff.write("</style>")
  113. ff.write("</head>")
  114. ff.write("<body>")
  115.  
  116. ff.write("<link href='http://fonts.googleapis.com/css?family=Exo+2:300,400' rel='stylesheet' type='text/css'>")
  117. ff.write("<style>")
  118.  
  119. ff.write("/* Eric Meyer's Reset CSS v2.0 - http://cssreset.com */")
  120. ff.write("html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{border:0;font-size:100%;font:inherit;vertical-align:baseline;margin:0;padding:0}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:none}table{border-collapse:collapse;border-spacing:0}")
  121.  
  122. ff.write("html,body{height:100%;}")
  123. ff.write("body{")
  124. ff.write("color: #444;")
  125. ff.write("background: url(http://www.babayara.com/wp-content/uploads/2013/08/vlcsnap-2013-08-24-23h14m34s7.png) no-repeat;")
  126. ff.write("}")
  127.  
  128. ff.write("#wrap{")
  129. ff.write("background-color: rgba(255, 255, 255, 0.6);")
  130. ff.write("width: 100%;")
  131. ff.write("height: 100%;")
  132. ff.write("padding-top: 50px;")
  133. ff.write("padding-left: 50px;")
  134. ff.write("line-height: 1.4;")
  135. ff.write("font-size: 24px;")
  136. ff.write("font-family: 'Exo 2', sans-serif;")
  137. ff.write("}")
  138.  
  139. ff.write("h3{")
  140. ff.write("font-weight: 300;")
  141. ff.write("}")
  142.  
  143. ff.write("h1{")
  144. ff.write("font-weight: 400;")
  145. ff.write("margin-bottom: 15px;")
  146. ff.write("}")
  147. ff.write("</style>")
  148. ff.write("<div id='wrap'>")
  149. ff.write("<h1>Bitcoin Node: MYIPADDRESS:8333<br \></h1>")
  150. ff.write("<h3>")
  151.  
  152. ff.write("Last Update: " + time.strftime("%H:%M:%S %Y-%m-%d %Z") + "<br \>\n")
  153. ff.write("Connections: " + str(info['connections']) + "<br \>\n")
  154. ff.write("Blocks: " + str(info['blocks']) + "<br \>\n")
  155. ff.write("Difficulty: " + str(info['difficulty']) + "<br \>\n")
  156.  
  157. ff.write("Location: MYLOCATION")
  158. ff.write("</h3>")
  159. ff.write("<br>Node created by <a href='https://bitcointalk.org/index.php?action=profile;u=58076'>Morblias</a>")
  160. ff.write("<br>Donate: 1Morb18DsDHNEv6TeQXBdba872ZSpiK9fY")
  161. ff.write("<br><a href='https://blockchain.info/address/1Morb18DsDHNEv6TeQXBdba872ZSpiK9fY'><img src='http://qrfree.kaywa.com/?l=1&amp;s=4&amp;d=1Morb18DsDHNEv6TeQXBdba872ZSpiK9fY' alt='QRCode'></a>")
  162. ff.write("</div>")
  163. ff.write("</body></html>")
  164.  
  165. ff.close()
  166. EOM
  167.  
  168. myipaddress=`wget -O - -q curlmyip.com`
  169. mylocation=`wget -q -O - freegeoip.net/csv | tr -d \" | awk -F"," '{ print $6 ", " $4 }'`
  170.  
  171. sed -i "s/RPCUSER/$randUser/g" $scriptFilename
  172. sed -i "s/RPCPASSWORD/$randPass/g" $scriptFilename
  173. sed -i "s/MYLOCATION/$mylocation/" $scriptFilename
  174. sed -i "s/MYIPADDRESS/$myipaddress/" $scriptFilename
  175.  
  176. chmod +x $scriptFilename
  177. $scriptFilename
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement