-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Install script] Support multiple networks #941
base: main
Are you sure you want to change the base?
Changes from all commits
73d09d0
1054e19
54a0c46
1ac5ebd
1cea391
f5e7fa0
8e162d2
a0fba55
e37bfa9
c808878
13a6947
25243bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -8,6 +8,9 @@ | |||||
YELLOW='\033[1;33m' | ||||||
NC='\033[0m' # No Color | ||||||
|
||||||
# DEV_NOTE: For testing purposes, you can change the branch name before merging to master. | ||||||
GENESIS_BRANCH="master" | ||||||
|
||||||
# Function to print colored output | ||||||
print_color() { | ||||||
COLOR=$1 | ||||||
|
@@ -23,19 +26,72 @@ | |||||
fi | ||||||
} | ||||||
|
||||||
# Function to install jq if not installed | ||||||
install_jq() { | ||||||
if ! command -v jq &> /dev/null; then | ||||||
print_color $YELLOW "Installing jq..." | ||||||
if [ -f /etc/debian_version ]; then | ||||||
apt-get update | ||||||
apt-get install -y jq | ||||||
elif [ -f /etc/redhat-release ]; then | ||||||
yum update -y | ||||||
yum install -y jq | ||||||
else | ||||||
print_color $RED "Unsupported distribution. Please install jq manually." | ||||||
exit 1 | ||||||
fi | ||||||
print_color $GREEN "jq installed successfully." | ||||||
else | ||||||
print_color $YELLOW "jq is already installed." | ||||||
fi | ||||||
} | ||||||
|
||||||
# Function to get user input | ||||||
get_user_input() { | ||||||
# Ask user which network to install | ||||||
echo "Which network would you like to install?" | ||||||
echo "1) testnet-alpha" | ||||||
echo "2) testnet-beta" | ||||||
echo "3) mainnet" | ||||||
read -p "Enter your choice (1-3): " network_choice | ||||||
okdas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
case $network_choice in | ||||||
1) NETWORK="testnet-alpha" ;; | ||||||
2) NETWORK="testnet-beta" ;; | ||||||
3) NETWORK="mainnet" ;; | ||||||
*) print_color $RED "Invalid choice. Exiting."; exit 1 ;; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
esac | ||||||
|
||||||
print_color $GREEN "You have chosen to install the $NETWORK network." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
read -p "Enter the desired username to run poktrolld (default: poktroll): " POKTROLL_USER | ||||||
POKTROLL_USER=${POKTROLL_USER:-poktroll} | ||||||
|
||||||
read -p "Enter the node moniker (default: $(hostname)): " NODE_MONIKER | ||||||
NODE_MONIKER=${NODE_MONIKER:-$(hostname)} | ||||||
|
||||||
read -p "Enter the chain-id (default: poktroll): " CHAIN_ID | ||||||
CHAIN_ID=${CHAIN_ID:-"poktroll"} | ||||||
# Update URLs to use the branch constant | ||||||
BASE_URL="https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/${GENESIS_BRANCH}/shannon/$NETWORK" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
SEEDS_URL="$BASE_URL/seeds" | ||||||
GENESIS_URL="$BASE_URL/genesis.json" | ||||||
|
||||||
# Download genesis.json and store it | ||||||
GENESIS_FILE="/tmp/genesis.json" | ||||||
curl -s -o "$GENESIS_FILE" "$GENESIS_URL" | ||||||
if [ $? -ne 0 ]; then | ||||||
print_color $RED "Failed to download genesis file. Please check your internet connection and try again." | ||||||
exit 1 | ||||||
fi | ||||||
|
||||||
# Extract chain_id from genesis.json | ||||||
CHAIN_ID=$(jq -r '.chain_id' < "$GENESIS_FILE") | ||||||
if [ -z "$CHAIN_ID" ]; then | ||||||
print_color $RED "Failed to extract chain_id from genesis file." | ||||||
exit 1 | ||||||
fi | ||||||
print_color $GREEN "Using chain_id: $CHAIN_ID from genesis file" | ||||||
|
||||||
# Fetch seeds from the provided URL | ||||||
SEEDS_URL="https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/master/shannon/alpha/testnet-validated.seeds" | ||||||
SEEDS=$(curl -s "$SEEDS_URL") | ||||||
if [ -z "$SEEDS" ]; then | ||||||
print_color $RED "Failed to fetch seeds from $SEEDS_URL. Please check your internet connection and try again." | ||||||
|
@@ -125,6 +181,7 @@ | |||||
print_color $GREEN "Cosmovisor set up successfully." | ||||||
} | ||||||
|
||||||
|
||||||
# Function to download and set up Poktrolld | ||||||
setup_poktrolld() { | ||||||
print_color $YELLOW "Setting up Poktrolld..." | ||||||
|
@@ -138,37 +195,62 @@ | |||||
exit 1 | ||||||
fi | ||||||
|
||||||
# Get the version genesis started from. We can't just use `latest` as the new binary won't sync from genesis. | ||||||
# We need to start syncing from scratch using the version that was used when the network started. | ||||||
POKTROLLD_VERSION=$(curl -s https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/master/shannon/alpha/testnet-validated.init-version) | ||||||
# Extract the version from genesis.json using jq | ||||||
POKTROLLD_VERSION=$(jq -r '.app_version' < "$GENESIS_FILE") | ||||||
print_color $YELLOW "Detected version from genesis: $POKTROLLD_VERSION" | ||||||
|
||||||
if [ -z "$POKTROLLD_VERSION" ]; then | ||||||
print_color $RED "Failed to extract version information from genesis file." | ||||||
exit 1 | ||||||
fi | ||||||
|
||||||
# Use the direct download link for the correct release | ||||||
RELEASE_URL="https://github.com/pokt-network/poktroll/releases/download/${POKTROLLD_VERSION}/poktroll_linux_${ARCH}.tar.gz" | ||||||
# Construct the release URL with proper version format | ||||||
RELEASE_URL="https://github.com/pokt-network/poktroll/releases/download/v${POKTROLLD_VERSION}/poktroll_linux_${ARCH}.tar.gz" | ||||||
print_color $YELLOW "Attempting to download from: $RELEASE_URL" | ||||||
|
||||||
# Download and extract directly as the POKTROLL_USER | ||||||
sudo -u "$POKTROLL_USER" bash << EOF | ||||||
mkdir -p \$HOME/.poktroll/cosmovisor/genesis/bin | ||||||
curl -L "$RELEASE_URL" | tar -zxvf - -C \$HOME/.poktroll/cosmovisor/genesis/bin | ||||||
if [ \$? -ne 0 ]; then | ||||||
echo "Failed to download or extract binary" | ||||||
exit 1 | ||||||
fi | ||||||
chmod +x \$HOME/.poktroll/cosmovisor/genesis/bin/poktrolld | ||||||
ln -sf \$HOME/.poktroll/cosmovisor/genesis/bin/poktrolld \$HOME/bin/poktrolld | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to these changes and likely out of scope but as this is the first time I'm reading this file, forgive my curiosity. 😅
Suggested change
My understanding is that this aligns with the XDG user directory specification, which has wide adoption [1, 2]. I'm noticing that we seem to be creating this - echo 'export PATH=\$HOME/bin:\$PATH' >> \$HOME/.profile [1] https://unix.stackexchange.com/questions/316765/which-distributions-have-home-local-bin-in-path |
||||||
source \$HOME/.profile | ||||||
EOF | ||||||
|
||||||
if [ $? -ne 0 ]; then | ||||||
print_color $RED "Failed to set up Poktrolld" | ||||||
exit 1 | ||||||
fi | ||||||
|
||||||
print_color $GREEN "Poktrolld set up successfully." | ||||||
} | ||||||
|
||||||
# Function to configure Poktrolld | ||||||
configure_poktrolld() { | ||||||
print_color $YELLOW "Configuring Poktrolld..." | ||||||
|
||||||
# Ask for confirmation to download the genesis file | ||||||
GENESIS_URL="https://raw.githubusercontent.com/pokt-network/pocket-network-genesis/master/shannon/alpha/testnet-validated.json" | ||||||
print_color $YELLOW "The script will download the genesis file from:" | ||||||
# Ask for confirmation to use the downloaded genesis file | ||||||
print_color $YELLOW "The script has downloaded the genesis file from:" | ||||||
print_color $YELLOW "$GENESIS_URL" | ||||||
read -p "Are you OK with downloading and using this genesis file? (y/N): " confirm_genesis | ||||||
read -p "Are you OK with using this genesis file? (y/N): " confirm_genesis | ||||||
if [[ ! $confirm_genesis =~ ^[Yy] ]]; then | ||||||
print_color $RED "Genesis file download cancelled. Exiting." | ||||||
print_color $RED "Genesis file usage cancelled. Exiting." | ||||||
Check warning on line 241 in tools/installer/full-node.sh GitHub Actions / misspell[misspell] tools/installer/full-node.sh#L241
Raw output
|
||||||
exit 1 | ||||||
fi | ||||||
|
||||||
# Detect external IP address | ||||||
EXTERNAL_IP=$(curl -s https://api.ipify.org) | ||||||
print_color $YELLOW "Detected external IP address: $EXTERNAL_IP" | ||||||
read -p "Is this your correct external IP address? (Y/n): " confirm_ip | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is anyone going to say no? Considering just commenting this out altogether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suspect there might be cases when the discovered IP address is not correct and requires adjustment. |
||||||
if [[ $confirm_ip =~ ^[Nn] ]]; then | ||||||
read -p "Please enter your external IP address: " custom_ip | ||||||
EXTERNAL_IP=${custom_ip:-$EXTERNAL_IP} | ||||||
fi | ||||||
|
||||||
sudo -u "$POKTROLL_USER" bash << EOF | ||||||
source \$HOME/.profile | ||||||
|
||||||
|
@@ -177,12 +259,9 @@ | |||||
echo "Poktrolld version: \$POKTROLLD_VERSION" | ||||||
|
||||||
poktrolld init "$NODE_MONIKER" --chain-id="$CHAIN_ID" --home=\$HOME/.poktroll | ||||||
curl -o \$HOME/.poktroll/config/genesis.json $GENESIS_URL | ||||||
if [ \$? -ne 0 ]; then | ||||||
echo "Failed to download genesis file. Please check your internet connection and try again." | ||||||
exit 1 | ||||||
fi | ||||||
cp "$GENESIS_FILE" \$HOME/.poktroll/config/genesis.json | ||||||
sed -i -e "s|^seeds *=.*|seeds = \"$SEEDS\"|" \$HOME/.poktroll/config/config.toml | ||||||
sed -i -e "s|^external_address *=.*|external_address = \"$EXTERNAL_IP:26656\"|" \$HOME/.poktroll/config/config.toml | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [linter-name (fail-on-found)] reported by reviewdog 🐶 |
||||||
EOF | ||||||
if [ $? -eq 0 ]; then | ||||||
print_color $GREEN "Poktrolld configured successfully." | ||||||
|
@@ -223,10 +302,28 @@ | |||||
print_color $GREEN "Systemd service set up and started successfully." | ||||||
} | ||||||
|
||||||
# Function to check if ufw is installed and open port 26656. We need to open the port to keep the network healthy. | ||||||
# By default, at least on Debian vultr, this port is not open to the internet. | ||||||
configure_ufw() { | ||||||
if command -v ufw &> /dev/null; then | ||||||
print_color $YELLOW "ufw is installed." | ||||||
read -p "Do you want to open port 26656 for p2p communication? (Y/n): " open_port | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wdyt about printing a line about how to undo this in the future? |
||||||
if [[ $open_port =~ ^[Yy] ]]; then | ||||||
ufw allow 26656 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to check the existing rules and only add one if it's not already present; otherwise, it seems that duplicate rules accumulate. See this chatGPT convo. |
||||||
print_color $GREEN "Port 26656 opened successfully." | ||||||
else | ||||||
print_color $YELLOW "Port 26656 not opened." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does landing in this conditional branch really guarantee that the port is not open? If not, I would suggest we rephrase the message to be more precise (e.g. |
||||||
fi | ||||||
else | ||||||
print_color $YELLOW "ufw is not installed. Skipping port configuration." | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
fi | ||||||
} | ||||||
|
||||||
# Main function | ||||||
main() { | ||||||
print_color $GREEN "Welcome to the Poktroll Full Node Install Script!" | ||||||
check_root | ||||||
install_jq | ||||||
get_user_input | ||||||
create_user | ||||||
install_dependencies | ||||||
|
@@ -235,7 +332,8 @@ | |||||
setup_poktrolld | ||||||
configure_poktrolld | ||||||
setup_systemd | ||||||
print_color $GREEN "Poktroll Full Node installation completed successfully!" | ||||||
configure_ufw | ||||||
print_color $GREEN "Poktroll Full Node installation for $NETWORK completed successfully!" | ||||||
print_color $YELLOW "You can check the status of your node with: sudo systemctl status cosmovisor.service" | ||||||
print_color $YELLOW "View logs with: sudo journalctl -u cosmovisor.service -f" | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.