benjaminvr

Untitled

Jan 16th, 2024
4,025
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.74 KB | None | 0 0
  1. #!/bin/bash
  2. # Tested on ubuntu 22.04, certbot v1.21.0, nyzoVerifier v642
  3.  
  4. # Update the server
  5. # Upgrade the server if necessary, remove the hashtag on the next line to do so
  6. sudo apt update -y
  7.  
  8. # Install dependencies, things the application relies on to function properly
  9. sudo apt install haveged -y
  10. sudo apt install openjdk-8-jdk -y
  11. sudo apt install supervisor -y
  12. sudo apt install certbot -y
  13.  
  14. # Create a special directory for your client
  15. mkdir /home/ubuntu && cd /home/ubuntu
  16.  
  17. # Allow network connectivity on the server level, check your virtual private server provider if this does not work. (todo add a page with overview comparing port blocks)
  18. sudo ufw allow 9444/tcp
  19. sudo ufw allow 9446/udp
  20. sudo ufw allow 80/tcp
  21. sudo ufw allow 80/udp
  22. sudo ufw allow 443/tcp
  23. sudo ufw allow 443/udp
  24. sudo ufw allow 8080/tcp
  25. sudo ufw allow 8080/udp
  26. sudo ufw allow 593/tcp
  27. sudo ufw allow 593/udp
  28. sudo ufw allow 22/tcp
  29. sudo ufw allow 22/udp
  30.  
  31. # Copy the source code to your machine
  32. git clone https://github.com/n-y-z-o/nyzoVerifier.git
  33.  
  34. # Java Gradlew converts this source code to machine readable binaries
  35. cd nyzoVerifier
  36. ./gradlew build
  37.  
  38. # Create a folder for the client you're going to put into production, ie. activating and enabling your client
  39. sudo mkdir -p /var/lib/nyzo/production
  40.  
  41. # The client will contact trusted verifiers first, if you provide none, your client will not work
  42. # The default trusted entry points are by default "nyzo.co" controlled, "nyzo.co" scans the mesh of active verifiers and couples ipv4 addresses to specific subdomains when nodes have proven to behave correctly
  43. # In addition to that a nyzo.org controlled node has been added
  44. # You can replace the domain or ipv4 addresses in this file at your discretion, when running multiple verifiers it is recommended to trust node(s) you're already the owner of
  45. sudo cp trusted_entry_points /var/lib/nyzo/production
  46. echo "verifier0.nyzo.org:9444" | sudo tee -a /var/lib/nyzo/production/trusted_entry_points > /dev/null
  47.  
  48. # Grant special rights to the script in order to be able to execute it
  49. chmod +x nyzoClient.sh
  50.  
  51. # Change some values, alternatively update the file itself
  52. sed -i -e 's/startretries=20/startretries=99999/g' nyzoClient.sh
  53.  
  54. # Run the script, it generates a supervisor configuration file for you
  55. ./nyzoClient.sh
  56.  
  57. # Copy this configuration file to the supervisor's production folders
  58. sudo cp nyzoClient.conf /etc/supervisor/conf.d
  59.  
  60. # Static preferences to make your client function properly, default port 80
  61. sudo echo -e "web_port=80" > /var/lib/nyzo/production/preferences
  62.  
  63. # Enter your client preferences, these get stored in the preferences file, adjusting the web ports should be sufficient for most users
  64. sudo echo -e "block_file_consolidator=disable
  65. start_historical_block_manager=1
  66. transaction_indexer_active=1
  67. start_web_listener=1
  68. " >> /var/lib/nyzo/production/preferences
  69.  
  70. reload_instance(){
  71.     # If trying to install multiple times, the log output is removed so the grep (searching the output file) will work
  72.     sudo rm /var/log/nyzo-client.log && sudo touch /var/log/nyzo-client.log
  73.  
  74.     # Reload the progress supervisor, awaits a clean output by status call
  75.     sudo supervisorctl reload
  76.  
  77.     while ! (supervisorctl status | grep --line-buffered RUNNING); do
  78.         :
  79.     done
  80.  
  81.     echo "Client started, pending launch end"
  82.  
  83.     # Await a successful client launch
  84.     while ! (supervisorctl tail -9 nyzo_client | grep --line-buffered command); do
  85.         :
  86.     done
  87.  
  88.     echo "Client launched successfully, network status: $(supervisorctl tail -100 nyzo_client | grep "frozen edge")"
  89.  
  90.     # Certificate using LetsEncrypt
  91.     # Create a temporary web forwarding proxy
  92.     sudo mkdir /var/lib/nyzo/production/webTemp
  93.  
  94.     # Create SSL certificate, fetch using HTTP to be aware of liveliness of the web listener content
  95.     while ! (curl client.nyzo.org | grep --line-buffered frozenEdge); do
  96.         :
  97.     done
  98.  
  99.     echo "Web listener live as indicated by HTTP fetch"
  100. }
  101.  
  102. #reload_instance
  103.  
  104. getfullchainpem() { [[ $1 =~ ^/etc/letsencrypt/live/(.*fullchain\.pem)$ ]] && echo "${BASH_REMATCH[1]}"; }
  105. getprivkeypem() { [[ $1 =~ ^/etc/letsencrypt/live/(.*privkey\.pem)$ ]] && echo "${BASH_REMATCH[1]}"; }
  106.  
  107.  
  108. # Create your SSL certificate
  109. # If you want the client to be reachable using a (sub)domain, enter details below
  110. # e.g. client.nyzo.org
  111. CLIENT_DOMAIN=""
  112. SSL_CERT_EMAIL=""
  113. # Your export password, minimum 16 chars
  114. SSL_EXPORT_PASSWORD=""
  115.  
  116. if [[ ! (-z $CLIENT_DOMAIN || -z $SSL_CERT_EMAIL || -z $SSL_EXPORT_PASSWORD) ]]; then
  117.     echo "Setting up your SSL certificate"
  118.    
  119.     CERTBOT_RESULT=$(sudo certbot certonly -n -m $SSL_CERT_EMAIL --agree-tos --webroot --webroot-map '{"'$CLIENT_DOMAIN'":"/var/lib/nyzo/production/webTemp"}' -d $CLIENT_DOMAIN --webroot-path '/var/lib/nyzo/production/webTemp')
  120.    
  121.     if [[ "$CERTBOT_RESULT" == *Successfully* ]]; then
  122.         echo "Successfully generated SSL certificate"
  123.        
  124.         echo -e -n "$CERTBOT_RESULT"
  125.        
  126.         CERT_PATH=$(getfullchainpem "$CERTBOT_RESULT")
  127.         KEY_PATH=$(getprivkeypem "$CERTBOT_RESULT")
  128.        
  129.         echo "$CERT_PATH"
  130.         echo "$KEY_PATH"
  131.        
  132.         sudo openssl pkcs12 -export -inkey "$KEY_PATH" -in "$CERT_PATH" generatedcert -out /var/lib/nyzo/production/ssl-keystore.p12
  133.        
  134.         echo "web_listener_keystore_path=/var/lib/nyzo/production/ssl-keystore.p12
  135. web_listener_keystore_password=" "$SSL_EXPORT_PASSWORD" | sudo tee -a /var/lib/nyzo/production/preferences > /dev/null
  136.        
  137.         reload_instance
  138.     else
  139.         echo "Failed to generate an SSL certificate, check your DNS records"
  140.     fi
  141. else
  142.     echo "Invalid domain, email or password length"
  143. fi
  144.  
  145. # When the server reboots, this will ensure the client starts as well
  146. # This will remove active cronjobs, so be careful
  147. echo "@reboot sudo supervisorctl reload" >> rebootcronjob
  148. crontab rebootcronjob
  149. rm rebootcronjob
  150.  
  151.  
  152.  
Advertisement
Add Comment
Please, Sign In to add comment