Guest User

Untitled

a guest
Jul 11th, 2018
1,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.78 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # TESTING IN PROGRESS
  4. #
  5. # An automated script to assist with installing Vertcoin full node(s)
  6. # -------------------------------------------------------------------
  7. # AUTHORS:
  8. # jochemin | Twitter: @jochemin | BTC Donations --> 3FM6FypcrSVhdHh7cpVQMrhPXPZ6zcXeYU
  9. # Sam Sepiol | Email: [email protected]
  10. # SPECIAL THANKS:
  11. # Thanks @b17z, this fork would not have happened without you. Thanks
  12. # for your help and inspiration.
  13. #
  14. # Dedicated to the Vertcoin community.
  15. # -------------------------------------------------------------------
  16. # Functions:
  17. # color functions
  18. # greentext
  19. # yellowtext
  20. # redtext
  21. # hd_detect | detect USB flash drive, format
  22. # hd_config | configure USB flash drive
  23. # swap_config | configure swap file to reside on formatted USB flash drive
  24. # user_input | take user input for rpcuser and rpcpass
  25. # network_addr | grab the LAN network addresses of the host running this script
  26. # secure | modify iptables to limit connections for security purposes
  27. # update_rasp | update the system
  28. # install_berkeley | install berkeley database 4.8 for wallet functionality
  29. # install_vertcoind | clone, build and install vertcoin core daemon
  30. # config_vertcoin | create ~/.vertcoin/vertcoin.conf to configure vertcoind
  31. # install_depends | install the required dependencies to run this script
  32. # grab_vtc_release | grab the latest vertcoind release from github
  33. # wait_for_continue | function for classic "Press spacebar to continue..."
  34. # grab_vtc_release | grab the latest vertcoind release from github
  35. # grab_bootstrap | grab the latest bootstrap.dat from alwayshashing
  36. # compile_or_compiled | prompt the user for input; would you like to build vertcoin core
  37. # load_blockchain | prompt the user for input; would you like to sideload the chain or
  38. # | grab the latest bootstrap.dat
  39. # prompt_p2pool | function to prompt user with option to install p2pool
  40. # install_p2pool | function to download and configure p2pool
  41. # user_intro | introduction to installation script, any key to continue
  42. # installation_report | report back key and contextual information
  43. # wait_for_continue | function for classic "Press spacebar to continue..."
  44. # config_crontab | function to configure crontab to start
  45. # -------------------------------------------------------------------
  46.  
  47. # clear the screen to begin
  48. clear
  49.  
  50. # install depends for detection; check for lshw, install if not
  51. if [ $(dpkg-query -W -f='${Status}' lshw 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
  52. echo "Installing required dependencies to run install-vertnode..."
  53. apt-get install lshw -y
  54. fi
  55.  
  56. # install depends for detection; check for gawk, install if not
  57. if [ $(dpkg-query -W -f='${Status}' gawk 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
  58. echo "Installing required dependencies to run install-vertnode..."
  59. apt-get install gawk -y
  60. fi
  61.  
  62. # fail on error; debug all lines
  63. set -eu -o pipefail
  64.  
  65. # colors for console output
  66. TEXT_RESET='\e[0m'
  67. TEXT_YELLOW='\e[0;33m'
  68. TEXT_RED='\e[1;31m'
  69. TEXT_GREEN='\e[0;32m'
  70.  
  71. # global script variables
  72. user=$(logname)
  73. userhome='/home/'$user
  74. FOLD1='/dev/'
  75. PUBLICIP="$(curl -s ipinfo.io/ip)"
  76. KERNEL="$(uname -a | awk '{print $2}')"
  77. # grab the first column of system name
  78. SYSTEM="$(lshw -short | grep system | awk -F'[: ]+' '{print $3" "$4" "$5" "$6" "$7" "$8" "$9" "$10" "$11}' | awk '{print $1}'
  79. )"
  80. # grab the default gateway ip address
  81. GATEWAY="$(ip r | grep "via " | awk -F'[: ]+' '{print $3}')"
  82. # grab the release name of operating system
  83. RELEASE="$(cat /etc/*-release | gawk -F= '/^NAME/{print $2}' | tr -d '"')"
  84. RAM="$(cat /proc/meminfo | grep MemTotal | awk -F'[: ]+' '{print $2}')"
  85. RAM_MIN='910000'
  86. ARCH="$(dpkg --print-architecture)"
  87. P2P=''
  88. INSTALLP2POOL=''
  89. BUILDVERTCOIN=''
  90. LOADBLOCKMETHOD=''
  91. MAXUPLOAD=''
  92. # find the active interface
  93. while true; do
  94. if [ "$SYSTEM" = "Raspberry" ]; then
  95. INTERFACE="$(ip -o link show | awk '{print $2,$9}' | grep UP | awk '{print $1}' | sed 's/:$//')"
  96. break
  97. elif [ "$SYSTEM" = "Rockchip" ]; then
  98. sudo apt-get install facter -y
  99. INTERFACE="$(sudo facter 2>/dev/null | grep ipaddress_et | awk '{print $1}' | sed 's/.*_//')"
  100. break
  101. else
  102. INTERFACE="$(ip -o link show | awk '{print $2,$9}' | grep UP | awk '{print $1}' | sed 's/:$//')"
  103. break
  104. fi
  105. done
  106. # check the active interface for its ip address
  107. while true; do
  108. # check if system is a raspberry pi, grep for only inet if true, print the 2nd column
  109. if [ "$SYSTEM" = "Raspberry" ]; then
  110. # grab ip address for raspberry pi
  111. LANIP="$(ifconfig $INTERFACE | grep "inet " | awk -F'[: ]+' '{print $3}' | awk 'NR==1{print $1}')"
  112. break
  113. elif [ "$SYSTEM" = "Rockchip" ]; then
  114. # grab ip address for rock64
  115. LANIP="$(sudo facter 2>/dev/null | grep ipaddress_et | awk '{print $3}')"
  116. break
  117. else
  118. # grap ip address for ubuntu
  119. LANIP="$(ifconfig $INTERFACE | grep "inet addr" | awk -F'[: ]+' '{print $4}')"
  120. break
  121. fi
  122. done
  123.  
  124. # -----------------------------------
  125.  
  126. # network_addr | grab the LAN network address range of the host running this script
  127. function network_addr {
  128. network_address=$(ip -o -f inet addr show | awk '/scope global/{sub(/[^.]+\//,"0/",$4);print $4}' | awk 'NR==1{print $1}')
  129. }
  130.  
  131. # wait_for_continue | function for classic "Press spacebar to continue..."
  132. function wait_for_continue {
  133. echo
  134. echo "DO NOT CONTINUE UNTIL THE BLOCKCHAIN HAS BEEN"
  135. echo "COMPLETELY COPIED OVER TO $userhome/.vertcoin/"
  136. echo
  137. read -n 1 -s -r -p "Press any key to continue..."
  138. echo
  139. }
  140.  
  141. # color functions
  142. function greentext(){
  143. echo -e -n "\e[0;32m$1"
  144. echo -e -n '\033[0m\n'
  145. }
  146. function yellowtext(){
  147. echo -e -n "\e[0;33m$1"
  148. echo -e -n '\033[0m\n'
  149. }
  150. function redtext(){
  151. echo -e -n "\e[1;31m$1"
  152. echo -e -n '\033[0m\n'
  153. }
  154.  
  155. # user_intro | introduction to installation script, any key to continue
  156. function user_intro {
  157. greentext 'Welcome to the Vertnode installation script!'
  158. echo
  159. greentext 'This script will install the Vertcoin software and allow for'
  160. greentext 'easy configuration of a Vertcoin full node. Additionally the'
  161. greentext 'script provides an optional installation and configuration of'
  162. greentext 'p2pool-vtc.'
  163. echo
  164. echo "To make this node a full node, please visit $GATEWAY with the"
  165. echo "URL bar of your web browser. Login to your router and continue"
  166. echo "to the port forwarding section and port forward..."
  167. echo "$LANIP TCP/UDP 5889"
  168. echo
  169. yellowtext 'What is a full node? It is a Vertcoin server that contains the'
  170. yellowtext 'full blockchain and propagates transactions throughout the Vertcoin'
  171. yellowtext 'network via peers). Playing its part to keep the Vertcoin peer-to-peer'
  172. yellowtext 'network healthy and strong.'
  173. echo
  174. read -n 1 -s -r -p "Press any key to continue..."
  175. }
  176.  
  177. # user_input | take user input for rpcuser and rpcpass
  178. function user_input {
  179. # check for USB flash drive
  180. while true; do
  181. clear
  182. echo -e "$TEXT_GREEN"
  183. read -p "Is the USB flash drive connected? It will be formatted. (y/n) " yn
  184. case $yn in
  185. [Yy]* ) hd_detect; break;; # if we have hd_config value we can configure it
  186. [Nn]* ) echo "Please connect USB flash drive and retry."; exit;;
  187. * ) echo "Do you wish to continue? (y/n) ";;
  188. esac
  189. done
  190. clear
  191. echo -e "$TEXT_GREEN"
  192. echo 'Vertcoin requires both an rpcuser & rpcpassword, enter your preferred values: '
  193. read -p 'Enter RPC user: ' rpcuser
  194. read -s -p 'Enter RPC password: ' rpcpass
  195. clear
  196. while true; do
  197. echo -e "$TEXT_GREEN"
  198. echo "What would you like the maximum amount of data (in MegaBytes) "
  199. echo "that you would like to allow your Vertcoin node to upload daily? "
  200. echo
  201. echo "Examples:"
  202. echo " 1024 MB = 1GB"
  203. echo " 2048 MB = 2GB"
  204. echo " 3072 MB = 3GB"
  205. echo " 4096 MB = 4GB"
  206. echo " 5120 MB = 5GB"
  207. echo
  208. read -p 'maxuploadtarget=' MAXUPLOAD
  209. # little bit of macgyvering here. this if statement uses -eq for something
  210. # other then it was intended. it checks for an integer, if it doesn't
  211. # find an one then it returns an error which is passed to /dev/null
  212. # and a value of false.
  213. if [ $MAXUPLOAD -eq $MAXUPLOAD 2>/dev/null ]
  214. then
  215. # if MAXUPLOAD is an integer break from loop and continue
  216. break
  217. else
  218. echo "$MAXUPLOAD isn't a number. Please try again."
  219. fi
  220. done
  221. }
  222.  
  223. # compile_or_compiled | prompt the user for input; would you like to build vertcoin core
  224. # | from source or would you like to grab the latest release binary?
  225. function compile_or_compiled {
  226. # if the system name contains RaspberryPiZero then compile from source
  227. # to avoid segmentation fault errors
  228. while true; do
  229. if echo "$SYSTEM" | grep -qe 'RaspberryPiZero.*' ; then
  230. echo "**************************************************************************"
  231. echo "HARDWARE = $SYSTEM"
  232. echo "Precompiled release binaries produce segmentation fault errors on $SYSTEM."
  233. echo
  234. echo "This script will build Vertcoin Core from source..."
  235. echo "NOTE: These operations will utilize the CPU @ 100% for a long time."
  236. echo "**************************************************************************"
  237. sleep 15
  238. BUILDVERTCOIN="install_vertcoind"
  239. break
  240. fi
  241. if [ "$SYSTEM" = "Rockchip" ]; then
  242. echo "**************************************************************************"
  243. echo "HARDWARE = $SYSTEM"
  244. echo "No precompiled releases are made available for $SYSTEM $ARCH."
  245. echo
  246. echo "This script will build Vertcoin Core from source..."
  247. echo "NOTE: These operations will utilize the CPU @ 100% for some time."
  248. echo "**************************************************************************"
  249. sleep 15
  250. BUILDVERTCOIN="install_vertcoind"
  251. break
  252. fi
  253. # prompt user if they would like to build from source
  254. read -p "Would you like to build Vertcoin from source? (y/n) " yn
  255. case $yn in
  256. # if user says yes, call install_vertcoind to compile source
  257. [Yy]* ) BUILDVERTCOIN="install_vertcoind"; break;;
  258. # if user says no, grab latest vtc release and break from loop
  259. [Nn]* ) BUILDVERTCOIN="grab_vtc_release"; break;;
  260. esac
  261. done
  262. }
  263.  
  264. # prompt_p2pool | function to prompt user with option to install p2pool
  265. function prompt_p2pool {
  266. while true; do
  267. echo
  268. read -p "Would you like install p2pool-vtc? (y/n) " yn
  269. case $yn$P2P in
  270. # if user says yes, call install_p2pool
  271. [Yy]* ) INSTALLP2POOL="install_p2pool"; break;;
  272. # if user says no, break from loop
  273. [Nn]* ) INSTALLP2POOL=""; break;;
  274. esac
  275. done
  276. }
  277.  
  278. # load_blockchain | prompt the user for input; would you like to sideload the
  279. # | the vertcoin blockchain or grab the latest bootstrap.dat
  280. function load_blockchain {
  281. # prompt user with menu selection
  282. echo
  283. PS3="Are you going to sideload the blockchain @ $LANIP:22 ? "
  284. options=("Yes, I will sideload the blockchain." "No, use bootstrap.dat instead." "No, sync on it's own.")
  285. select opt in "${options[@]}"
  286. do
  287. case $opt in
  288. "Yes, I will sideload the blockchain.")
  289. LOADBLOCKMETHOD="wait_for_continue"
  290. break
  291. ;;
  292. "No, use bootstrap.dat instead.")
  293. LOADBLOCKMETHOD="grab_bootstrap"
  294. break
  295. ;;
  296. "No, sync on it's own.")
  297. LOADBLOCKMETHOD=""
  298. break
  299. ;;
  300. * ) echo "Invalid option, please try again";;
  301. esac
  302. done
  303. }
  304.  
  305. # init_script
  306. function init_script {
  307. echo
  308. greentext 'Initializing Vertnode installation script...'
  309. echo
  310. yellowtext '*****************************************'
  311. if [ "$BUILDVERTCOIN" == "install_vertcoind" ]; then
  312. yellowtext 'Vertcoin Installation | Build from source'
  313. else
  314. yellowtext 'Vertcoin Installation | Latest vertcoin-core release'
  315. fi
  316. if [ "$INSTALLP2POOL" == "install_p2pool" ]; then
  317. yellowtext 'P2Pool-vtc Installation | True'
  318. else
  319. yellowtext 'P2Pool-vtc Installation | False'
  320. fi
  321. if [ "$LOADBLOCKMETHOD" == "wait_for_continue" ]; then
  322. yellowtext 'Blockchain Loading Method | Sideload the blockchain'
  323. elif [ "$LOADBLOCKMETHOD" == "grab_bootstrap" ]; then
  324. yellowtext 'Blockchain Loading Method | Grab latest bootstrap.dat'
  325. else
  326. yellowtext 'Blockchain Loading Method | Sync on its own'
  327. fi
  328. yellowtext '*****************************************'
  329. sleep 10
  330. }
  331.  
  332. # update_rasp | update the system
  333. function update_rasp {
  334. yellowtext 'Initializing system update...'
  335. sudo apt-get update
  336. sudo apt-get upgrade -y
  337. sudo apt-get autoremove -y
  338. greentext 'Successfully updated system!'
  339. echo
  340. # check if reboot is needed
  341. if [ -f /var/run/reboot-required ]; then
  342. redtext 'Reboot required!'
  343. fi
  344. }
  345.  
  346. # install_depends | install the required dependencies to run this script
  347. function install_depends {
  348. yellowtext 'Installing package dependencies...'
  349. sudo apt-get install -y build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils python3 libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev git fail2ban dphys-swapfile unzip
  350. greentext 'Successfully installed required dependencies!'
  351. echo
  352. }
  353.  
  354. # secure | modify iptables to limit connections for security purposes
  355. function secure {
  356. yellowtext 'Configuring firewall...'
  357. # install the dependancy
  358. sudo apt-get install ufw -y
  359. # call the function network_addr
  360. network_addr
  361. # configure ufw firewall
  362. echo
  363. ufw default deny incoming
  364. ufw default allow outgoing
  365. ufw allow from $network_address to any port 22 comment 'allow SSH from local LAN'
  366. ufw allow 5889 comment 'allow vertcoin core'
  367. ufw --force enable
  368. systemctl enable ufw
  369. ufw status
  370. echo
  371. greentext 'Successfully configured firewall!'
  372. echo
  373. }
  374.  
  375. # hd_detect | USB flash drive detect; prompt for formatting
  376. function hd_detect {
  377. # grep the output of lsblk -dlnb for the sda device
  378. # pass it to awk and print the fourth column of that row
  379. # that value = the size of the sda device
  380. usbsize=$(lsblk -dlnb | grep sda | awk '{print $4}')
  381. # list block devices that are greater than or equal to 15GB, cut the first three characters
  382. # make sure the microSD card that holds raspbian is 8GB or smaller to ensure find_drive picks
  383. # the correct block device.
  384. find_drive="$(lsblk -dlnb | awk '{if($3 == 1){print}}' | awk '{print $1}')"
  385. drive=$FOLD1$find_drive
  386. drive_size="$(df -h "$drive" | sed 1d | awk '{print $2}')"
  387. while true; do
  388. echo -e "$TEXT_RED"
  389. read -p "$drive_size $drive will be formatted. Do you wish to continue? (y/n) " yn
  390. case $yn in
  391. [Yy]* ) DRIVE_CONF=true; break;;
  392. [Nn]* ) echo "This script needs to format the entire flash drive.";
  393. echo -e "$TEXT_RESET"; exit;;
  394. * ) echo "Do you wish to continue? (y/n) ";;
  395. esac
  396. echo -e "$TEXT_RESET"
  397. done
  398. }
  399.  
  400. # hd_config | configure USB flash drive
  401. function hd_config {
  402. drive=$drive
  403. if mount | grep "$drive" > /dev/null; then
  404. umount -l "$drive" > /dev/null
  405. fi
  406. yellowtext 'Formatting USB flash drive...'
  407. # format usb disk as ext4 filesystem
  408. sudo mkfs.ext4 -F "$drive" -L storage
  409. greentext 'Successfully formatted flash drive!'
  410. # locally declare UUID as the value given by blkid
  411. UUID="$(blkid -o value -s UUID "$drive")"
  412. echo
  413. yellowtext 'Creating Vertcoin data folder...'
  414. VTCDIR='/home/'$user'/.vertcoin'
  415. mkdir -p "$VTCDIR"
  416. yellowtext 'Modifying fstab configuration...'
  417. echo
  418. sudo sed -i".bak" "/$UUID/d" /etc/fstab
  419. echo "UUID=$UUID $VTCDIR ext4 defaults,noatime 0 0" >> /etc/fstab
  420. if mount | grep "$drive" > /dev/null; then
  421. :
  422. else
  423. sudo mount -a
  424. fi
  425. chmod 777 $VTCDIR
  426. greentext 'Successfully configured USB flash drive!'
  427. echo
  428. }
  429.  
  430. # swap_config | configure swap file to reside on formatted flash drive
  431. function swap_config {
  432. # !! notify user the ability to begin sideloading blockchain
  433. yellowtext '********************************************************************'
  434. greentext ' NOTICE: Sideloading is now available'
  435. echo
  436. echo " If you intend on sideloading the blockchain please use an "
  437. echo " SFTP client such as WinSCP or FileZilla to copy the BLOCKS"
  438. echo " and CHAINSTATE folder to /home/$user/.vertcoin/"
  439. yellowtext '--------------------------------------------------------------------'
  440. greentext ' HOW TO CONNECT: '
  441. echo
  442. echo " Using WinSCP or FileZilla please connect to... "
  443. echo
  444. echo " IP Address: $LANIP"
  445. echo " Port: 22 "
  446. echo " Username: $user "
  447. echo " Password: (pi default pass: raspberry)"
  448. echo " (rock64 default pass: rock64)"
  449. yellowtext '********************************************************************'
  450. echo
  451. # continue and configure swap
  452. yellowtext 'Configuring swap file to reside on USB flash drive...'
  453. sudo -u "$user" mkdir -p /home/"$user"/.vertcoin/swap
  454. # dd will take a few minutes to complete
  455. echo
  456. echo "This may take awhile, please be patient."
  457. dd if=/dev/zero of=/home/"$user"/.vertcoin/swap/swap.file bs=1M count=2148
  458. chmod 600 /home/"$user"/.vertcoin/swap/swap.file
  459. sudo sed -i".bak" "/CONF_SWAPFILE/d" /etc/dphys-swapfile
  460. sudo sed -i".bak" "/CONF_SWAPSIZE/d" /etc/dphys-swapfile
  461. echo "CONF_SWAPFILE=/home/$user/.vertcoin/swap/swap.file" >> /etc/dphys-swapfile
  462. # set aside 2GB of memory for swap
  463. echo "CONF_SWAPSIZE=2048" >> /etc/dphys-swapfile
  464. mkswap /home/"$user"/.vertcoin/swap/swap.file
  465. swapon /home/"$user"/.vertcoin/swap/swap.file
  466. echo "/home/$user/.vertcoin/swap/swap.file none swap defaults 0 0" >> /etc/fstab
  467. echo
  468. greentext 'Successfully configured swap space!'
  469. echo
  470. }
  471.  
  472. # install_berkeley | install berkeley database 4.8 for wallet functionality
  473. function install_berkeley {
  474. rock64system=""
  475. yellowtext 'Installing Berkeley (4.8) database...'
  476. sudo -u "$user" mkdir -p "$userhome"/bin
  477. cd "$userhome"/bin
  478. sudo -u "$user" wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz
  479. sudo -u "$user" tar -xzvf db-4.8.30.NC.tar.gz
  480. cd db-4.8.30.NC/build_unix/
  481. # check if system is rock64, specify build type if true
  482. if echo "$SYSTEM" | grep Rock64 ; then
  483. ../dist/configure --enable-cxx --build=aarch64-unknown-linux-gnu
  484. else
  485. ../dist/configure --enable-cxx
  486. fi
  487. make
  488. sudo make install
  489. # if the system is a rock64 export the location of berkeleydb
  490. if [ $KERNEL = "rock64" ]; then
  491. export LD_LIBRARY_PATH=/usr/local/BerkeleyDB.4.8/lib/
  492. fi
  493. greentext 'Successfully installed Berkeley (4.8) database!'
  494. echo
  495. }
  496.  
  497. # install_vertcoind | clone, build and install vertcoin core daemon
  498. function install_vertcoind {
  499. install_berkeley
  500. # continue on compiling vertcoin from source
  501. yellowtext 'Installing Vertcoin Core...'
  502. rm -fR "$userhome"/bin/vertcoin-core
  503. cd "$userhome"/bin
  504. git clone https://github.com/vertcoin-project/vertcoin-core.git
  505. while true; do
  506. if [ $KERNEL = "rock64" ]; then
  507. cd "$userhome"/bin/vertcoin-core/
  508. ./autogen.sh
  509. ./configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib" --enable-upnp-default --build=aarch64-unknown-linux-gnu
  510. break
  511. elif [ "$RAM" -gt "$RAM_MIN" ]; then
  512. # if RAM is greater than 910MB configure without memory flags
  513. cd "$userhome"/bin/vertcoin-core/
  514. ./autogen.sh
  515. ./configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib" --enable-upnp-default
  516. break
  517. else
  518. # if RAM is less than 910MB configure with memory flags
  519. cd "$userhome"/bin/vertcoin-core/
  520. ./autogen.sh
  521. ./configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib" --enable-upnp-default CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768"
  522. break
  523. fi
  524. done
  525. cd "$userhome"/bin/vertcoin-core/
  526. make
  527. sudo make install
  528. greentext 'Successfully installed Vertcoin Core!'
  529. echo
  530. }
  531.  
  532. # grab_vtc_release | grab the latest vertcoind release from github
  533. function grab_vtc_release {
  534. while true; do
  535. if [ "$RELEASE" = "Debian GNU/Linux" ]; then
  536. break
  537. elif [ "$RELEASE" = "Ubuntu" ]; then
  538. add-apt-repository ppa:bitcoin/bitcoin -y
  539. sudo apt-get update
  540. sudo apt-get install libdb4.8-dev libdb4.8++-dev -y
  541. break
  542. fi
  543. done
  544. # grab the latest version number; store in variable $VERSION
  545. export VERSION=$(curl -s "https://github.com/vertcoin-project/vertcoin-core/releases/latest" | grep -o 'tag/[v.0-9]*' | awk -F/ '{print $2}')
  546. # grab the latest version release; deviation in release naming scheme will break this
  547. # release naming scheme needs to be: 'vertcoind-v(release#)-linux-armhf.zip' to work
  548. wget https://github.com/vertcoin-project/vertcoin-core/releases/download/$VERSION/vertcoind-v$VERSION-linux-$ARCH.zip
  549. unzip vertcoind-v$VERSION-linux-$ARCH.zip
  550. # clean up
  551. rm vertcoind-v$VERSION-linux-$ARCH.zip
  552. # move vertcoin binaries to /usr/bin/
  553. mv vertcoind vertcoin-tx vertcoin-cli /usr/bin/
  554. }
  555.  
  556. # grab_bootstrap | grab the latest bootstrap.dat
  557. function grab_bootstrap {
  558. # check package manager for pv, install if not
  559. if [ $(dpkg-query -W -f='${Status}' pv 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
  560. sudo apt-get install pv
  561. fi
  562. # clone megadown script to download bootstrap
  563. echo
  564. cd $userhome
  565. git clone https://github.com/tonikelope/megadown.git
  566. cd $userhome/megadown/
  567. echo
  568. # grab bootstrap.dat generated by sam sepiol
  569. echo "Downloading latest bootstrap.dat (Generated 7/8/2018)..."
  570. # download boostrap.dat
  571. ./megadown 'https://mega.nz/#!eSRSjaLL!wY5gE6JhL2zODZIARoTCr2eNKgNIwBzmz9yIxZiu_R4' -o $userhome/.vertcoin/
  572. cd $userhome
  573. # clean up, megadown not needed
  574. rm -r megadown/
  575. echo
  576. echo "Successfully downloaded bootstrap.dat!"
  577. echo
  578. }
  579.  
  580. # config_crontab | function to configure crontab to start
  581. function config_crontab {
  582. VTCRON=$({ crontab -l -u $user 2>/dev/null; echo '@reboot vertcoind -daemon'; } | crontab -u $user - )
  583. echo
  584. yellowtext 'Configuring Crontab...'
  585. yellowtext '** vertcoind | start on reboot'
  586. $VTCRON
  587. echo
  588. greentext 'Successfully configured Crontab!'
  589. }
  590.  
  591. # config_vertcoin | create ~/.vertcoin/vertcoin.conf to configure vertcoind
  592. function config_vertcoin {
  593. # echo values into a file named vertcoin.conf
  594. echo "server=1" >> /home/"$user"/.vertcoin/vertcoin.conf
  595. echo "rpcuser=$rpcuser" >> /home/"$user"/.vertcoin/vertcoin.conf
  596. echo "rpcpassword=$rpcpass" >> /home/"$user"/.vertcoin/vertcoin.conf
  597. echo 'dbcache=100' >> /home/"$user"/.vertcoin/vertcoin.conf
  598. echo 'maxmempool=100' >> /home/"$user"/.vertcoin/vertcoin.conf
  599. echo 'maxorphantx=10' >> /home/"$user"/.vertcoin/vertcoin.conf
  600. echo 'maxmempool=50' >> /home/"$user"/.vertcoin/vertcoin.conf
  601. echo 'maxconnections=40' >> /home/"$user"/.vertcoin/vertcoin.conf
  602. echo "maxuploadtarget=$MAXUPLOAD" >> /home/"$user"/.vertcoin/vertcoin.conf
  603. echo 'usehd=1' >> /home/"$user"/.vertcoin/vertcoin.conf
  604. # configure permissions for user access
  605. cd "$userhome"/.vertcoin/
  606. chmod 777 vertcoin.conf
  607. }
  608.  
  609. # install_p2pool | function to download and configure p2pool
  610. function install_p2pool {
  611. echo
  612. yellowtext 'Installing p2pool-vtc...'
  613. # install dependencies for p2pool-vtc
  614. sudo apt-get install python-rrdtool python-pygame python-scipy python-twisted python-twisted-web python-imaging python-pip libffi-dev -y
  615. # clone p2pool-vtc
  616. # grab latest p2pool-vtc release
  617. cd "$userhome"/
  618. sudo -u "$user" wget "https://github.com/vertcoin-project/p2pool-vtc/archive/v0.3.0-rc1.zip"
  619. sudo -u "$user" unzip v0.3.0-rc1.zip
  620. sudo rm v0.3.0-rc1.zip
  621. cd "$userhome"/p2pool-vtc-0.3.0-rc1/
  622. sudo python setup.py install
  623. # download alternative web frontend and install
  624. echo
  625. yellowtext 'Installing alternate web frontend for p2pool-vtc...'
  626. echo
  627. cd "$userhome"/
  628. sudo -u "$user" git clone https://github.com/hardcpp/P2PoolExtendedFrontEnd.git
  629. cd "$userhome"/P2PoolExtendedFrontEnd/
  630. sudo -u "$user" mv * /home/$user/p2pool-vtc-0.3.0-rc1/web-static/
  631. cd "$userhome"/
  632. # clean up
  633. rm -r P2PoolExtendedFrontEnd/
  634. echo
  635. greentext 'Successfully installed alternate web frontend for p2pool-vtc!'
  636. echo
  637. getnewaddress=$(sudo -u $user vertcoin-cli getnewaddress "" legacy)
  638. # grab the LAN IP range and store it in variable network_address
  639. network_address=$(ip -o -f inet addr show | awk '/scope global/{sub(/[^.]+\//,"0/",$4);print $4}')
  640. # open both ports for network 1 & network 2
  641. ufw allow 9171 comment 'allow --network 1 mining port'
  642. ufw allow 9181 comment 'allow --network 2 mining port'
  643. ufw allow 9346 comment 'allow --network 1 p2p port'
  644. ufw allow 9347 comment 'allow --network 2 p2p port'
  645. ufw --force enable
  646. ufw status
  647. # begin configuration of p2pool
  648. yellowtext 'Configuring p2pool-vtc...'
  649. echo
  650. echo "Network 1 | Recommended for large miners with hashrate larger than 100Mh"
  651. echo "Network 2 | Recommended for small miners with hashrate lower than 100Mh"
  652. # prompt user with menu for network selection
  653. echo
  654. PS3="What network do you want to configure with p2pool-vtc? "
  655. options=("Network 1" "Network 2")
  656. select opt in "${options[@]}"
  657. do
  658. case $opt in
  659. "Network 1")
  660. p2poolnetwork=""
  661. break
  662. ;;
  663. "Network 2")
  664. p2poolnetwork="2"
  665. break
  666. ;;
  667. * ) echo "Invalid option, please select option 1 or 2.";;
  668. esac
  669. done
  670. # echo our values into a file named start-p2pool.sh
  671. echo "#!/bin/bash" >> /home/"$user"/start-p2pool.sh
  672. echo "cd p2pool-vtc-0.3.0-rc1" >> /home/"$user"/start-p2pool.sh
  673. # sleep an additional 2 minutes to make sure vertcoind is alive and can give an address
  674. sleep 120
  675. echo "python run_p2pool.py --net vertcoin$p2poolnetwork -a $getnewaddress --max-conns 8 --outgoing-conns 4" >> /home/"$user"/start-p2pool.sh
  676. # permission the script for execution
  677. chmod +x start-p2pool.sh
  678. echo
  679. greentext 'Successfully configured p2pool-vtc!'
  680. echo
  681. yellowtext 'Configuring Crontab...'
  682. yellowtext '** p2pool-vtc | start on reboot'
  683. # define p2poolcron variable and store command to echo new cronjob into crontab
  684. P2POOLCRON=$({ crontab -l -u $user 2>/dev/null; echo "@reboot sleep 120; nohup sh /home/$user/start-p2pool.sh"; } | crontab -u $user - )
  685. # echo cronjob value into crontab
  686. $P2POOLCRON
  687. echo
  688. yellowtext 'Starting p2pool-vtc...'
  689. cd "$userhome"/
  690. sudo -u "$user" nohup sh start-p2pool.sh &
  691. }
  692.  
  693. # initiate_blockchain | take user response from load_blockchain and execute
  694. function initiate_blockchain {
  695. # check if system = Raspberry Pi Zero and force building from source
  696. if echo "$SYSTEM" | grep -qe 'RaspberryPiZero.*' ; then
  697. install_vertcoind
  698. fi
  699. if [ "$LOADBLOCKMETHOD" == "wait_for_continue" ]; then
  700. # if user selected to install p2pool, then install it
  701. wait_for_continue
  702. echo
  703. greentext 'Waiting two minutes for Vertcoin Core to start...'
  704. echo
  705. greentext 'Starting Vertcoin Core...'
  706. echo
  707. sudo -u "$user" vertcoind -daemon
  708. sleep 120
  709. elif [ "$LOADBLOCKMETHOD" == "grab_bootstrap" ]; then
  710. grab_bootstrap
  711. echo
  712. greentext 'Waiting two minutes for Vertcoin Core to start...'
  713. echo
  714. greentext 'Starting Vertcoin Core...'
  715. echo
  716. sudo -u "$user" vertcoind -daemon -loadblock=$userhome/.vertcoin/bootstrap.dat
  717. sleep 120
  718. else
  719. # else just sync vertcoin on its own
  720. echo
  721. greentext 'Waiting two minutes for Vertcoin Core to start...'
  722. echo
  723. greentext 'Starting Vertcoin Core...'
  724. echo
  725. sudo -u "$user" vertcoind -daemon
  726. sleep 120
  727. fi
  728. }
  729.  
  730. # post installation_report | report back key and contextual information
  731. function installation_report {
  732. echo
  733. echo "VERTNODE INSTALLATION SCRIPT COMPLETE"
  734. echo "-------------------------------------"
  735. echo "Public IP Address: $PUBLICIP"
  736. echo "Local IP Address: $LANIP"
  737. echo "Default Gateway: $GATEWAY"
  738. echo "Vertcoin Data: $userhome/.vertcoin/"
  739. echo
  740. echo "p2pool-vtc -----------"
  741. echo "Network 1: $LANIP:9171"
  742. echo "Network 2: $LANIP:9181"
  743. echo "-------------------------------------"
  744. echo
  745. echo "To make this node a full node, please visit $GATEWAY with the"
  746. echo "URL bar of your web browser. Login to your router and continue"
  747. echo "to the port forwarding section and port forward..."
  748. echo "$LANIP TCP/UDP 5889"
  749. echo
  750. echo "What is a full node? It is a Vertcoin server that contains the"
  751. echo "full blockchain and propagates transactions throughout the Vertcoin"
  752. echo "network via peers). Playing its part to keep the Vertcoin peer-to-peer"
  753. echo "network healthy and strong."
  754. echo
  755. echo "Useful commands to know:"
  756. echo "------------------------------------------------------------------------------"
  757. echo " htop | task manager / resource monitor"
  758. echo " ifconfig | display network interface IP addresses"
  759. echo " vertcoin-cli getblockchaininfo | display blockchain information"
  760. echo " vertcoin-cli getblockcount | display current number of blocks"
  761. echo " vertcoin-cli getconnectioncount | display number of connections"
  762. echo " vertcoin-cli getnettotals | display total number of bytes sent/recv"
  763. echo " vertcoin-cli getnewaddress | generate bech32 (segwit) address"
  764. echo " vertcoin-cli getnewaddress "\"""\"" legacy | generate legacy address"
  765. echo
  766. echo " # display latest vertcoin log information: "
  767. echo " tail -f ~/.vertcoin/debug.log"
  768. echo
  769. if [ "$INSTALLP2POOL" == "install_p2pool" ]; then
  770. # is p2pool was installed display this information
  771. echo " # display latest p2pool log information: "
  772. echo " tail -f ~/p2pool-vtc-0.3.0-rc1/data/vertcoin$p2poolnetwork/log"
  773. else
  774. # else do nothing and proceed
  775. :
  776. fi
  777. echo "------------------------------------------------------------------------------"
  778. }
  779.  
  780. # -------------BEGIN-MAIN-------------------
  781.  
  782. # check for sudo when running the script
  783. if [ "$(id -u)" -ne 0 ]; then
  784. redtext "Please run this script with sudo!" >&2
  785. exit 1
  786. fi
  787. # clear the screen
  788. clear
  789. user_intro
  790. clear
  791. # check parameters
  792. while test $# -gt 0
  793. do
  794. key="$1"
  795. if [ "$key" = "secure" ];
  796. then
  797. secure; exit 1
  798. else
  799. redtext 'Unknown parameter'; exit 1
  800. fi
  801. done
  802. # call user_input function | take user input for rpcuser and rpcpass
  803. clear
  804. user_input
  805. clear
  806. compile_or_compiled
  807. clear
  808. prompt_p2pool
  809. clear
  810. # prompt user to load blockchain
  811. load_blockchain
  812. clear
  813. init_script
  814. echo
  815. # call update_rasp function | update the system
  816. update_rasp
  817. echo
  818. # call install_depends function | install the required dependencies to run this script
  819. install_depends
  820. echo
  821. # call secure function | modify iptables to limit connections for security purposes
  822. secure
  823. echo
  824. # configure USB flash drive ; call hd_config function, then call swap_config function
  825. if [ "$DRIVE_CONF" = "true" ]; then
  826. hd_config
  827. swap_config
  828. fi
  829. # call install_vertcoind | clone, build and install vertcoin core daemon
  830. echo
  831. # check for user response to compile from source
  832. if [ "$BUILDVERTCOIN" == "install_vertcoind" ]; then
  833. # if user selected to compile vertcoin from source, then compile
  834. install_vertcoind
  835. else
  836. # grab latest vtc release
  837. grab_vtc_release
  838. fi
  839. # configure crontab for vertcoin
  840. config_crontab
  841. # call config_vertcoin | create ~/.vertcoin/vertcoin.conf to configure vertcoind
  842. config_vertcoin
  843. # execute on blockchain loading method
  844. initiate_blockchain
  845. # check for user response to install p2pool
  846. if [ "$INSTALLP2POOL" == "install_p2pool" ]; then
  847. # if user selected to install p2pool, then install it
  848. install_p2pool
  849. else
  850. # else do nothing and proceed
  851. :
  852. fi
  853. # if user chose sideload blockchain wait for continue
  854. if [ "$LOADBLOCKMETHOD" == "wait_for_continue" ]; then
  855. # if user selected to sideload blockchain then wait to make sure
  856. # the blockchain has been completely copied over before starting vertcoin
  857. wait_for_continue
  858. break
  859. else
  860. # else proceed starting vertcoin and initializing sync
  861. :
  862. fi
  863. # display post installation results
  864. installation_report
Advertisement
Add Comment
Please, Sign In to add comment