|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Define the ASCII art |
| 4 | +art=$(echo " |
| 5 | + __ _______ _ ____ ___ __ __ _____ _____ ___ |
| 6 | + \ \ / / ____| | / ___/ _ \| \/ | ____| |_ _/ _ \\ |
| 7 | + \ \ /\ / /| _| | | | | | | | | |\/| | _| | || | | | |
| 8 | + \ V V / | |___| |__| |__| |_| | | | | |___ | || |_| | |
| 9 | + \_/\_/ |_____|_____\____\___/|_| |_|_____| |_| \___/ |
| 10 | +
|
| 11 | +
|
| 12 | + ______ ______ _____ ____ _ _ ___ ____ _____ |
| 13 | + / ___\ \ / / __ )| ____| _ \| \ | |/ _ \| _ \| ____| |
| 14 | + | | \ V /| _ \| _| | |_) | \| | | | | | | | _| |
| 15 | + | |___ | | | |_) | |___| _ <| |\ | |_| | |_| | |___ |
| 16 | + \____| |_| |____/|_____|_| \_\_| \_|\___/|____/|_____| |
| 17 | +
|
| 18 | + ..',,;;,,'.. |
| 19 | + .;ok0NWMMMMMMMMMMMMWX0xl,. |
| 20 | + .ckNMMMMMMMMMMMMMMMMMMMMMMMMMMXd;. |
| 21 | + ,OWMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMWd. |
| 22 | + .OMMMMMMMMMMMMMWNXK0000KXWWMMMMMMMMMMMMMx. |
| 23 | + :WMMMMMMMMMXxc,. .;oONMMMMMMMMMN' |
| 24 | + .WMMMMMMMXl. ,xWMMMMMMMN. |
| 25 | + lMMMMMMWc .kMMMMMMM: . |
| 26 | + .x; ;MMMMMM: 'cll:'. .;cllc. kMMMMMM, .X: |
| 27 | + ;NMx OMMMMM. .oxxxxd:. .lxxxdxc. ;MMMMMO oMMO.. |
| 28 | + oMMMW'..kWMMMd 'loddo; .:oddoc. 0MMMMx...NMMMK, |
| 29 | + cMMMMMX;..;0MMMk. ... ... .0MMM0;..:XMMMMMO |
| 30 | + KMMMMMMWk;..'oKMWO:. .c0MMXx,..lKMMMMMMMM. |
| 31 | + .KMMMMMMMMMNd, .:d0NXkl:'.. ..':okXWKkl,..l0WMMMMMMMMMN |
| 32 | + 'cWMMMMMMMMMMMXc ..;ldxO0000KK00Okdo:,.. dNMMMMMMMMMMMWc |
| 33 | + cWMMMMMMMMMMMMK:' cXMMMMMMMMMMMMNc |
| 34 | + :0MMMMMMMMMMMMWo. dWMMMMMMMMMMMWO: |
| 35 | + 'cKMMMMMMMMMMMMx. .xMMMMMMMMMMMWO;' |
| 36 | + ;kNMMMMMMMMMMd dMMMMMMMMMMKo' |
| 37 | + ckNMMMMMMMW, 'WMMMMMMW0o' |
| 38 | + 'l0NMMMMd.. cMMMW0o;. |
| 39 | +") |
| 40 | + |
| 41 | +# Display the ASCII art |
| 42 | +echo "$art" |
| 43 | + |
| 44 | +# Step 1: Ask user to enter a domain name |
| 45 | +message=$(cat <<EOF |
| 46 | +For installation, you will need: |
| 47 | + - Domain name to provide endpoints |
| 48 | + - Open ports: |
| 49 | + - Port 80 (HTTP) |
| 50 | + - Port 443 (HTTPS) |
| 51 | + - Port 26656 (BOSTROM) |
| 52 | + - Port 4001 (IPFS) |
| 53 | + - Email to receive SSL certificates (optional) |
| 54 | +EOF |
| 55 | +) |
| 56 | + |
| 57 | +echo "$message" |
| 58 | + |
| 59 | +read -p "STEP 1: Please enter domain name: " domain |
| 60 | + |
| 61 | +# Step 1.1: Domain name clarification check |
| 62 | +while true; do |
| 63 | + read -p "Do you want to use the domain name '$domain'? (y/n): " confirmation |
| 64 | + if [[ $confirmation == "y" || $confirmation == "Y" ]]; then |
| 65 | + break |
| 66 | + elif [[ $confirmation == "n" || $confirmation == "N" ]]; then |
| 67 | + read -p "Enter the domain name: " domain |
| 68 | + else |
| 69 | + echo "Invalid input. Please enter 'y' or 'n'." |
| 70 | + fi |
| 71 | +done |
| 72 | + |
| 73 | +# Step 2: Insert domain name into the .env file |
| 74 | +sed -i -E "s/^(DOMAIN=).*/\1${domain}/" .env |
| 75 | + |
| 76 | +# Step 3: Insert domain name into prometheus.yml |
| 77 | +sed -i -e "s#- https://.*:9115#- https://$domain:9115#" \ |
| 78 | + -e "s#- https://rpc\..*/block?height=7278626#- https://rpc.$domain/block?height=7278626#" \ |
| 79 | + -e "s#- https://lcd\..*/node_info#- https://lcd.$domain/node_info#" \ |
| 80 | + -e "s#- https://index\..*/console/#- https://index.$domain/console/#" \ |
| 81 | + -e "s#- https://ipfs\..*/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme#- https://ipfs.$domain/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/readme#" prometheus.yml |
| 82 | + |
| 83 | +# Step 3.1: Display updated lines from prometheus.yml |
| 84 | +echo "Following endpoint list will be provided by your Hero" |
| 85 | +grep -E "(https?|rpc\.|lcd\.|index\.|ipfs\.|$domain:9115)" prometheus.yml | grep -v -e "module: \[http_prometheus\]" -e "- targets: # Target to probe with https." |
| 86 | +echo "Domain name has been updated successfully." |
| 87 | + |
| 88 | +# Step 3.2: Ping rpc.<DOMAIN_NAME> and display IP address |
| 89 | +rpc_domain="rpc.$domain" |
| 90 | +echo "STEP 2: Pinging $rpc_domain..." |
| 91 | +ip_address=$(ping -c 1 $rpc_domain | grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -1) |
| 92 | + |
| 93 | +echo "The IP address of $rpc_domain is: $ip_address" |
| 94 | + |
| 95 | +# Step 3.3: Confirm IP address ownership |
| 96 | +read -p "Does the IP address $ip_address belong to you? (y/n): " ip_confirmation |
| 97 | + |
| 98 | +if [[ $ip_confirmation == "y" || $ip_confirmation == "Y" ]]; then |
| 99 | + echo "IP address ownership confirmed." |
| 100 | +else |
| 101 | + echo "Please ensure the correct IP address is assigned to your domain and try again." |
| 102 | +fi |
| 103 | + |
| 104 | +# Step 4: Ask user if they want to use email for SSL certificates |
| 105 | +read -p "STEP 3: Do you want to use email to obtain SSL certificates? (y/n): " use_email |
| 106 | + |
| 107 | +if [[ $use_email == "y" || $use_email == "Y" ]]; then |
| 108 | + while true; do |
| 109 | + read -p "Enter email: " email |
| 110 | + read -p "Do you want to use the email '$email'? (y/n): " confirmation |
| 111 | + if [[ $confirmation == "y" || $confirmation == "Y" ]]; then |
| 112 | + sed -i -E "s/^(EMAIL=).*/\1${email}/" .env |
| 113 | + sed -i '/certbot:/,/command: certonly/ s/--register-unsafely-without-email/--email ${EMAIL}/' docker-compose-init.yml docker-compose.yml |
| 114 | + break |
| 115 | + elif [[ $confirmation == "n" || $confirmation == "N" ]]; then |
| 116 | + continue |
| 117 | + else |
| 118 | + echo "Invalid input. Please enter 'y' or 'n'." |
| 119 | + fi |
| 120 | + done |
| 121 | +fi |
| 122 | + |
| 123 | +if [[ $use_email == "n" || $use_email == "N" ]]; then |
| 124 | + sed -i '/certbot:/,/command: certonly/ s/--email ${EMAIL}/--register-unsafely-without-email/' docker-compose-init.yml docker-compose.yml |
| 125 | +fi |
| 126 | + |
| 127 | +# Step 5: Open Ports |
| 128 | +# Check if ufw is active |
| 129 | +echo "STEP 4: Enable ufw and open ports" |
| 130 | +ufw_status=$(sudo ufw status | grep -o "Status: active") |
| 131 | + |
| 132 | +if [[ "$ufw_status" == "Status: active" ]]; then |
| 133 | + echo "ufw is already active." |
| 134 | + read -p "The following ports will be open: |
| 135 | + - Port 80 (HTTP) |
| 136 | + - Port 443 (HTTPS) |
| 137 | + - Port 26656 (BOSTROM) |
| 138 | + - Port 4001 (IPFS) |
| 139 | + Do you want to allow these ports and start running Hero node? (y/n): " answer |
| 140 | + |
| 141 | + if [[ "$answer" == "y" || "$answer" == "Y" ]]; then |
| 142 | + sudo ufw allow 80 |
| 143 | + sudo ufw allow 443 |
| 144 | + sudo ufw allow 26656 |
| 145 | + sudo ufw allow 4001 |
| 146 | + echo "Ports allowed successfully." |
| 147 | + else |
| 148 | + echo "WARNING: If the required ports are not open, the application may not function properly." |
| 149 | + echo "WARNING: Please configure your firewall to allow the following ports after the script finishes:" |
| 150 | + fi |
| 151 | +else |
| 152 | + read -p "ufw is not active. Do you want to activate ufw and allow the required ports? (y/n): " activate_ufw |
| 153 | + |
| 154 | + if [[ "$activate_ufw" == "y" || "$activate_ufw" == "Y" ]]; then |
| 155 | + sudo ufw enable |
| 156 | + sudo ufw allow 80 |
| 157 | + sudo ufw allow 443 |
| 158 | + sudo ufw allow 26656 |
| 159 | + sudo ufw allow 4001 |
| 160 | + echo "UFW activated and ports allowed successfully." |
| 161 | + else |
| 162 | + echo "WARNING: If the required ports are not open, the application may not function properly." |
| 163 | + echo "WARNING: Please configure your firewall to allow the following ports after the script finishes:" |
| 164 | + fi |
| 165 | +fi |
| 166 | + |
| 167 | +# Step 6: Check nvidia |
| 168 | +echo "STEP 5: Checking if the drivers are installed" |
| 169 | + |
| 170 | +nvidia-smi &> /dev/null |
| 171 | +if [[ $? -eq 0 ]]; then |
| 172 | + echo "Success! Nvidia driver is installed." |
| 173 | + else |
| 174 | + echo "Error: Nvidia driver is not installed or not detected." |
| 175 | +fi |
| 176 | + |
| 177 | +# Step 7: Start docker-compose-init.yml |
| 178 | +echo "STEP 6: Getting certificates to start your node" |
| 179 | +docker-compose -f docker-compose-init.yml up -d |
| 180 | + |
| 181 | +# Step 8: Check if docker-compose-init.yml started successfully |
| 182 | +if [ $? -eq 0 ]; then |
| 183 | + echo "docker-compose-init.yml started successfully." |
| 184 | + echo "STEP 7: Wait a minute for your Hero Node to start" |
| 185 | + # Step 8: Start docker-compose.yml |
| 186 | + sleep 60 |
| 187 | + docker-compose -f docker-compose.yml up -d |
| 188 | +else |
| 189 | + echo "Failed to start docker-compose-init.yml. Aborting." |
| 190 | +fi |
0 commit comments