Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 104 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,108 @@
#!/bin/bash
echo "setting up the validator key"
# This script builds a Canopy node.
echo " ____ _ _ _ ___ ______ __"
echo " / ___| / \ | \ | |/ _ \| _ \ \ / /"
echo "| | / _ \ | \| | | | | |_) \ V / "
echo "| |___ / ___ \| |\ | |_| | __/ | | "
echo " \____/_/ \_\_| \_|\___/|_| |_| "
echo
echo "Welcome to Canopy Setup!"
echo

CONFIG_FILE=setup.conf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add an example of this file in the repo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do if we like this approach.


# Default canopy branch to build, can be overridden in config file
BRANCH=beta-0.1.3

# Function to show current setup configuration
show_config() {
echo "Loaded setup configuration:"
echo
echo "SETUP_TYPE: $SETUP_TYPE"
echo "DOMAIN: $DOMAIN"
echo "ACME_EMAIL: $ACME_EMAIL"
echo "BRANCH: $BRANCH"
echo
}

# Function to save config to a file
save_config() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is not idempotent, although the setup is meant to be ran once, I think we should protect against people who may want to use this as a way to update their files (or may run it multiple times if they're having issues for whatever reason)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

digging more into the code there's an autoload option so even more reasons to make this idempotent

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the config file is only overwritten if the user opts to enter the values again.

The main purpose was for headless installs and running multiple times. Thinking again however I think we can remove the save functionality altogether and just have it read the file if it is present.

echo "SETUP_TYPE=${SETUP_TYPE}" > "${CONFIG_FILE}"
echo "DOMAIN=${DOMAIN}" >> "${CONFIG_FILE}"
echo "ACME_EMAIL=${ACME_EMAIL}" >> "${CONFIG_FILE}"
echo "BRANCH=${BRANCH}" >> "${CONFIG_FILE}"
echo "Setup configuration saved to ${CONFIG_FILE}"
}
# Function to load config from a file
load_config() {
config_file="${CONFIG_FILE}"
if [[ -f "${config_file}" ]]; then
source "${config_file}"
else
echo "Config file ${config_file} not found"
return 1
fi
}

if [[ -f "$CONFIG_FILE" ]]; then
should_load_config() {
# Auto-load if AUTOLOAD is present
if grep -q "AUTOLOAD=yes\|AUTOLOAD=true" $CONFIG_FILE; then
return 0
fi
# Ask user for confirmation
read -p "Load previous setup configuration? (Y/n): " LOAD_CONFIG
echo
[[ "$LOAD_CONFIG" != "n" && "$LOAD_CONFIG" != "N" ]]
}
if should_load_config; then
load_config
show_config
fi
fi

# Function to read SETUP, DOMAIN and ACME_EMAIL configuration options from user
read_variables() {
# Ask user for setup type
echo "Please select setup type:"
echo "1) simple (only contains the node containers)"
echo "2) full (contains the node containers and the monitoring stack)"
read -p "Enter your choice (1 or 2): " SETUP_CHOICE
# Validate and set SETUP
while [[ "$SETUP_CHOICE" != "1" && "$SETUP_CHOICE" != "2" ]]; do
echo "Invalid choice. Please enter 1 for simple or 2 for full."
read -p "Enter your choice (1 or 2): " SETUP_CHOICE
done
if [[ "$SETUP_CHOICE" == "1" ]]; then
SETUP_TYPE="simple"
else
SETUP_TYPE="full"
fi
# Ask for domain input
read -p "Please enter the domain [default: localhost]: " DOMAIN
if [[ -z "$DOMAIN" ]]; then
DOMAIN="localhost"
fi
# Ask for email input
read -p "Please enter email to validate the domain against [default: [email protected]]: " ACME_EMAIL
if [[ -z "$ACME_EMAIL" ]]; then
ACME_EMAIL="[email protected]"
fi
}

# Prompt user for variables if SETUP_TYPE is not present
if [[ -z "$SETUP_TYPE" ]]; then
# Read variables from user
read_variables
# Save them to $CONFIG_FILE
save_config
fi

# Remove any previous canopy-config container still around
docker stop canopy-config > /dev/null 2>&1
docker rm canopy-config > /dev/null 2>&1

echo "Setting up the validator key"
docker pull canopynetwork/canopy && \
docker run --user root -it -p 50000:50000 -p 50001:50001 -p 50002:50002 -p 50003:50003 -p 9001:9001 --name canopy-config --volume ${PWD}/canopy_data/node1/:/root/.canopy/ canopynetwork/canopy && \
docker stop canopy-config && docker rm canopy-config && \
Expand Down