From d5b156c6a002c591f82c88260ace2144638f725b Mon Sep 17 00:00:00 2001 From: David Maldonado Date: Thu, 23 Jan 2025 11:02:07 -0500 Subject: [PATCH 1/8] feat: updated installation script --- Installation Script/install_sn27.sh | 650 +++++++++++++++++----------- 1 file changed, 407 insertions(+), 243 deletions(-) diff --git a/Installation Script/install_sn27.sh b/Installation Script/install_sn27.sh index 14454e05..418e49a7 100644 --- a/Installation Script/install_sn27.sh +++ b/Installation Script/install_sn27.sh @@ -1,7 +1,7 @@ #!/bin/bash set -u -# enable command completion +# Enable command completion set -o history -o histexpand python="python3" @@ -11,14 +11,6 @@ abort() { exit 1 } -getc() { - local save_state - save_state=$(/bin/stty -g) - /bin/stty raw -echo - IFS= read -r -n 1 -d '' "$@" - /bin/stty "$save_state" -} - exit_on_error() { exit_code=$1 last_command=${@:2} @@ -28,10 +20,69 @@ exit_on_error() { fi } +# Minimal logger +ohai() { + echo "==> $*" +} + +############################################## +# 1. Detect if it is AUTOMATED or manual mode +############################################## + +# AUTOMATED can be set as an environment variable, for example "true" +AUTOMATED="${AUTOMATED:-false}" + +# Or parse a --automated flag +if [[ "${1:-}" == "--automated" ]]; then + AUTOMATED="true" +fi + +WANDB_ENV="${WANDB_KEY:-}" + +COLDKEY_SEED="${COLDKEY_SEED:-}" + +HOTKEY_SEED="${HOTKEY_SEED:-}" +ask_user_for_wandb_key() { + read -rp "Enter WANDB_API_KEY (leave blank if none): " WANDB_ENV +} + +########################################## +# Insert WANDB_API_KEY into .env +########################################## +inject_wandb_env() { + local env_example="/home/ubuntu/Compute-Subnet/.env.example" + local env_path="/home/ubuntu/Compute-Subnet/.env" + + ohai "Configuring .env for Compute-Subnet..." + + if [[ ! -f "$env_path" ]] && [[ -f "$env_example" ]]; then + ohai "Copying .env.example to .env" + sudo -u ubuntu cp "$env_example" "$env_path" + fi + + if [[ -n "$WANDB_ENV" ]]; then + ohai "Updating WANDB_API_KEY in .env" + sudo -u ubuntu sed -i "s|^WANDB_API_KEY=.*|WANDB_API_KEY=\"$WANDB_ENV\"|" "$env_path" + else + ohai "No WANDB_API_KEY provided. Skipping replacement in .env." + fi + + sudo chown ubuntu:ubuntu "$env_path" + ohai "Done configuring .env" +} + +getc() { + local save_state + save_state=$(/bin/stty -g) + /bin/stty raw -echo + IFS= read -r -n 1 -d '' "$@" + /bin/stty "$save_state" +} + wait_for_user() { local c echo - echo "Press RETURN to continue or any other key to abort" + echo "Press ENTER to continue or any other key to abort" getc c # we test for \r and \n because some stuff does \r instead if ! [[ "$c" == $'\r' || "$c" == $'\n' ]]; then @@ -39,39 +90,11 @@ wait_for_user() { fi } -shell_join() { - local arg - printf "%s" "$1" - shift - for arg in "$@"; do - printf " " - printf "%s" "${arg// /\ }" - done -} - -# string formatters -if [[ -t 1 ]]; then - tty_escape() { printf "\033[%sm" "$1"; } -else - tty_escape() { :; } -fi -tty_mkbold() { tty_escape "1;$1"; } -tty_underline="$(tty_escape "4;39")" -tty_blue="$(tty_mkbold 34)" -tty_red="$(tty_mkbold 31)" -tty_bold="$(tty_mkbold 39)" -tty_reset="$(tty_escape 0)" - -ohai() { - printf "${tty_blue}==>${tty_bold} %s${tty_reset}\n" "$(shell_join "$@")" -} - -# Things can fail later if `pwd` doesn't exist. -# Also sudo prints a warning message for no good reason -cd "/usr" || exit 1 - +################################################################################ +# PRE-INSTALL +################################################################################ linux_install_pre() { - sudo apt-get update + sudo apt-get update sudo apt-get install --no-install-recommends --no-install-suggests -y apt-utils curl git cmake build-essential ca-certificates # Add Docker's official GPG key: @@ -79,166 +102,338 @@ linux_install_pre() { sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc sudo chmod a+r /etc/apt/keyrings/docker.asc - # Add the repository to Apt sources: + # Add Docker's repository: echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ - $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ - sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" \ + | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update - - # Install the latest version of Docker sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + exit_on_error $? "docker-installation" +} - exit_on_error $? +################################################################################ +# SETUP VENV +################################################################################ +linux_setup_venv() { + ohai "Installing python3.10-venv (if not present)" + sudo apt-get install -y python3.10-venv + + ohai "Creating Python venv in /home/ubuntu/venv" + # Create the venv as the ubuntu user + sudo -u ubuntu -H python3 -m venv /home/ubuntu/venv + exit_on_error $? "venv-creation" + + # Upgrade pip inside the venv + ohai "Upgrading pip in the new venv" + sudo -u ubuntu -H /home/ubuntu/venv/bin/pip install --upgrade pip + exit_on_error $? "venv-pip-upgrade" + + if [[ "$AUTOMATED" == "true" ]]; then + ohai "Adding 'source /home/ubuntu/venv/bin/activate' to ~/.bashrc (automated mode)" + echo "source /home/ubuntu/venv/bin/activate" | sudo tee -a /home/ubuntu/.bashrc + sudo chown ubuntu:ubuntu /home/ubuntu/.bashrc + else + ohai "Skipping automatic venv activation in ~/.bashrc (manual mode)" + fi } -linux_install_subtensor() { - ohai "Cloning subtensor into ~/subtensor" - mkdir -p ~/subtensor - sudo apt install -y git - git clone https://github.com/opentensor/subtensor.git - cd subtensor +################################################################################ +# COMPUTE-SUBNET +################################################################################ +linux_install_compute_subnet() { + ohai "Cloning or updating Compute-Subnet into /home/ubuntu/Compute-Subnet" + sudo mkdir -p /home/ubuntu/Compute-Subnet + + if [ ! -d /home/ubuntu/Compute-Subnet/.git ]; then + # If not cloned, we clone it + sudo git clone https://github.com/neuralinternet/Compute-Subnet.git /home/ubuntu/Compute-Subnet/ + else + # If already cloned, we pull + cd /home/ubuntu/Compute-Subnet + sudo git pull --ff-only + fi + + # Ensure that "ubuntu" is the owner of the folder + sudo chown -R ubuntu:ubuntu /home/ubuntu/Compute-Subnet + + ohai "Installing Compute-Subnet dependencies (including correct Bittensor version)" + cd /home/ubuntu/Compute-Subnet + + # Install inside the venv + sudo -u ubuntu -H /home/ubuntu/venv/bin/pip install -r requirements.txt + sudo -u ubuntu -H /home/ubuntu/venv/bin/pip install --no-deps -r requirements-compute.txt + + # Editable installation of Compute-Subnet + sudo -u ubuntu -H /home/ubuntu/venv/bin/pip install -e . + exit_on_error $? "compute-subnet-installation" + + # Install extra libraries for OpenCL + sudo apt -y install ocl-icd-libopencl1 pocl-opencl-icd + + ohai "Starting Docker service, adding user to docker, installing 'at' package" + sudo groupadd docker 2>/dev/null || true + sudo usermod -aG docker ubuntu + sudo systemctl start docker + sudo apt install -y at + + cd /home/ubuntu } +################################################################################ +# PYTHON +################################################################################ linux_install_python() { - which $python - if [[ $? != 0 ]] ; then + if ! command -v "$python" >/dev/null 2>&1; then ohai "Installing python" - sudo apt-get install --no-install-recommends --no-install-suggests -y $python + sudo apt-get install --no-install-recommends --no-install-suggests -y "$python" else - ohai "Updating python" - sudo apt-get install --only-upgrade $python + ohai "Upgrading python" + sudo apt-get install --only-upgrade "$python" fi - exit_on_error $? - ohai "Installing python tools" - sudo apt-get install --no-install-recommends --no-install-suggests -y $python-pip $python-dev - exit_on_error $? -} - -linux_update_pip() { - PYTHONPATH=$(which $python) - ohai "You are using python@ $PYTHONPATH$" - ohai "Installing python tools" - $python -m pip install --upgrade pip -} + exit_on_error $? "python-install" -linux_install_bittensor() { - ohai "Cloning bittensor@master into ~/.bittensor/bittensor" - mkdir -p ~/.bittensor/bittensor - git clone https://github.com/opentensor/bittensor.git ~/.bittensor/bittensor/ 2> /dev/null || (cd ~/.bittensor/bittensor/ ; git fetch origin master ; git checkout master ; git pull --ff-only ; git reset --hard ; git clean -xdf) - ohai "Installing bittensor" - $python -m pip install -e ~/.bittensor/bittensor/ - exit_on_error $? + ohai "Installing python dev tools" + sudo apt-get install --no-install-recommends --no-install-suggests -y \ + "${python}-pip" "${python}-dev" + exit_on_error $? "python-dev" } -linux_increase_ulimit(){ - ohai "Increasing ulimit to 1,000,000" - prlimit --pid=$PPID --nofile=1000000 +linux_update_pip() { + ohai "Upgrading pip (system-wide)" + "$python" -m pip install --upgrade pip + exit_on_error $? "pip-upgrade" } +################################################################################ +# PM2 +################################################################################ linux_install_pm2() { - sudo apt update - sudo apt install -y npm + sudo apt-get update + sudo apt-get install -y npm sudo npm install pm2 -g } +################################################################################ +# NVIDIA DOCKER +################################################################################ linux_install_nvidia_docker() { ohai "Installing NVIDIA Docker support" - cd - distribution=$(. /etc/os-release;echo $ID$VERSION_ID) + local distribution=$(. /etc/os-release; echo $ID$VERSION_ID) + curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - - curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list - sudo apt update - sudo apt-get install -y nvidia-container-toolkit - sudo apt install -y nvidia-docker2 -} + curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list \ + | sudo tee /etc/apt/sources.list.d/nvidia-docker.list -linux_install_compute_subnet() { - ohai "Cloning Compute-Subnet into ~/Compute-Subnet" - mkdir -p ~/Compute-Subnet - git clone https://github.com/neuralinternet/Compute-Subnet.git ~/Compute-Subnet/ 2> /dev/null || (cd ~/Compute-Subnet/ ; git pull --ff-only ; git reset --hard ; git clean -xdf) - - ohai "Installing Compute-Subnet dependencies" - cd ~/Compute-Subnet - $python -m pip install -r requirements.txt - $python -m pip install --no-deps -r requirements-compute.txt - $python -m pip install -e . - sudo apt -y install ocl-icd-libopencl1 pocl-opencl-icd - - ohai "Starting Docker service, adding user to docker, and installing 'at' package" - sudo groupadd docker - sudo usermod -aG docker $USER - sudo systemctl start docker - sudo apt install -y at - - cd ~ - exit_on_error $? + sudo apt-get update -y + sudo apt-get install -y nvidia-container-toolkit nvidia-docker2 + + ohai "NVIDIA Docker installed" } -linux_install_hashcat() { - wget https://hashcat.net/files/hashcat-6.2.6.tar.gz - tar xzvf hashcat-6.2.6.tar.gz - cd hashcat-6.2.6/ - sudo make - sudo make install - export PATH=$PATH:/usr/local/bin/ - echo "export PATH=$PATH">>~/.bashrc - cd ~ +detect_ubuntu_version() { + source /etc/os-release 2>/dev/null || { + echo "Cannot detect /etc/os-release. Not an Ubuntu-based system?" + return 1 + } + + if [[ "$ID" == "ubuntu" && "$VERSION_ID" == "22.04" ]]; then + echo "ubuntu-22.04" + else + echo "unsupported" + fi } +################################################################################ +# CUDA INSTALLATION (NO removal of existing drivers) +################################################################################ linux_install_nvidia_cuda() { - wget https://developer.download.nvidia.com/compute/cuda/12.3.1/local_installers/cuda-repo-ubuntu2204-12-3-local_12.3.1-545.23.08-1_amd64.deb - sudo dpkg -i cuda-repo-ubuntu2204-12-3-local_12.3.1-545.23.08-1_amd64.deb - sudo cp /var/cuda-repo-ubuntu2204-12-3-local/cuda-*-keyring.gpg /usr/share/keyrings/ - sudo apt-get update - sudo apt-get -y install cuda-toolkit-12-3 - sudo apt-get -y install -y cuda-drivers - export CUDA_VERSION=cuda-12.3 - export PATH=$PATH:/usr/local/$CUDA_VERSION/bin - export LD_LIBRARY_PATH=/usr/local/$CUDA_VERSION/lib64 - echo "">>~/.bashrc - echo "PATH=$PATH">>~/.bashrc - echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH">>~/.bashrc -} + local distro=$(detect_ubuntu_version) + + if [[ "$distro" == "unsupported" ]]; then + ohai "Detected a distro/version that this script does not support for CUDA. Please install manually following NVIDIA docs." + return 0 + fi + + + if command -v nvidia-smi >/dev/null 2>&1 || command -v nvcc >/dev/null 2>&1; then + ohai "CUDA/NVIDIA drivers found; skipping re-installation." + return + fi + + ohai "CUDA/NVIDIA drivers not found. Installing for Ubuntu 22.04..." + + # STEPS pinned approach Ubuntu 22.04 + # 1. build-essential ... + sudo apt-get update + sudo apt-get install -y build-essential dkms linux-headers-$(uname -r) + + # 2. pinned file + wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin + sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600 + + # 3. local .deb + wget https://developer.download.nvidia.com/compute/cuda/12.6.3/local_installers/cuda-repo-ubuntu2204-12-6-local_12.6.3-560.35.05-1_amd64.deb \ + -O /tmp/cuda-repo.deb + sudo dpkg -i /tmp/cuda-repo.deb + sudo cp /var/cuda-repo-ubuntu2204-12-6-local/cuda-*-keyring.gpg /usr/share/keyrings/ + sudo apt-get update + + # 4. Install toolkit + sudo apt-get -y install cuda-toolkit-12-6 -linux_install_ufw() { - sudo apt update - sudo apt install -y ufw - sudo ufw allow 22/tcp - sudo ufw allow 4444 + # 5. Environment variables + ohai "Configuring environment variables for CUDA 12.6" + { + echo "" + echo "# Added by NVIDIA CUDA install script" + echo "export PATH=/usr/local/cuda-12.6/bin:\$PATH" + echo "export LD_LIBRARY_PATH=/usr/local/cuda-12.6/lib64:\$LD_LIBRARY_PATH" + } | sudo tee -a /home/ubuntu/.bashrc + + sudo chown ubuntu:ubuntu /home/ubuntu/.bashrc + source /home/ubuntu/.bashrc + + ohai "CUDA 12.6 installed successfully on Ubuntu 22.04!" } +############################################ +# Manual mode: request port range +############################################ linux_configure_ufw() { - echo "Please enter the port range for UFW (e.g., 2000-5000):" - read -p "Enter port range (start-end): " port_range - - if [[ $port_range =~ ^[0-9]+-[0-9]+$ ]]; then - start_port=$(echo $port_range | cut -d'-' -f1) - end_port=$(echo $port_range | cut -d'-' -f2) + sudo apt-get update && sudo apt-get install -y ufw + + if [[ "$AUTOMATED" == "true" ]]; then + local default_range="2000-5000" + ohai "AUTOMATED mode: enabling UFW for port range $default_range" + sudo ufw allow "${default_range}/tcp" + sudo ufw enable + ohai "UFW configured automatically for port range $default_range" - if [[ $start_port -lt $end_port ]]; then - sudo ufw allow $start_port:$end_port/tcp - sudo ufw enable - echo "UFW configured successfully with port range $port_range" + else + echo "Please enter the port range for UFW (e.g., 2000-5000):" + read -p "Enter port range (start-end): " port_range + + # Verificar formato "start-end" + if [[ "$port_range" =~ ^[0-9]+-[0-9]+$ ]]; then + start_port=$(echo "$port_range" | cut -d'-' -f1) + end_port=$(echo "$port_range" | cut -d'-' -f2) + + if [[ $start_port -lt $end_port ]]; then + ohai "Enabling UFW for port range $start_port-$end_port" + sudo ufw allow "${start_port}:${end_port}/tcp" + sudo ufw enable + ohai "UFW configured successfully with port range $port_range" + else + echo "Invalid port range. The start port should be less than the end port." + exit 1 + fi else - echo "Invalid port range. The start port should be less than the end port." + echo "Invalid port range format. Please use the format: start-end (e.g., 2000-5000)" exit 1 fi + fi +} + +################################################################################ +# ULIMIT (CONFIGURABLE) +################################################################################ +linux_increase_ulimit(){ + if [[ "$AUTOMATED" == "true" ]]; then + ohai "AUTOMATED mode: Increasing ulimit to 1,000,000" + prlimit --pid=$$ --nofile=1000000 + else + ohai "Current open-files limit (ulimit -n) is: $(ulimit -n)" + read -rp "Increase ulimit to 1,000,000? [y/N]: " do_ulimit + do_ulimit="${do_ulimit,,}" + if [[ "$do_ulimit" == "y" || "$do_ulimit" == "yes" ]]; then + ohai "Raising ulimit to 1,000,000..." + prlimit --pid=$$ --nofile=1000000 + else + ohai "Leaving ulimit as is." + fi + fi +} + +regen_bittensor_wallet() { + if [[ "$AUTOMATED" == "true" ]]; then + ohai "Running wallet regeneration in AUTOMATED mode." + + if [[ -z "$COLDKEY_SEED" || -z "$HOTKEY_SEED" ]]; then + ohai "No COLDKEY_SEED/HOTKEY_SEED found in environment. Skipping wallet regen." + return + else + ohai "Regenerating coldkey with COLDKEY_SEED from env..." + btcli wallet regen_coldkey --name "default_cold" --mnemonic $COLDKEY_SEED + exit_on_error $? "regen_coldkey" + + ohai "Regenerating hotkey with HOTKEY_SEED from env..." + btcli wallet regen_hotkey --name "default_hot" --mnemonic $HOTKEY_SEED + exit_on_error $? "regen_hotkey" + + ohai "Wallet regeneration completed in AUTOMATED mode." + fi + + else + ohai "Do you want to regenerate (create) a Bittensor wallet? [y/N]" + read -r wallet_choice + wallet_choice="${wallet_choice,,}" # a minúsculas + + if [[ "$wallet_choice" == "y" || "$wallet_choice" == "yes" ]]; then + echo "Do you want to use test seeds or enter your own? [test/custom]" + read -r seed_choice + seed_choice="${seed_choice,,}" + + if [[ "$seed_choice" == "test" ]]; then + local cold_test_seed="example_cold_seed_for_testing_only" + local hot_test_seed="example_hot_seed_for_testing_only" + + ohai "Regenerating coldkey with test seed..." + btcli wallet regen_coldkey --name "default" --seed "$cold_test_seed" --overwrite + exit_on_error $? "regen_coldkey" + + ohai "Regenerating hotkey with test seed..." + btcli wallet regen_hotkey --name "default" --seed "$hot_test_seed" --overwrite + exit_on_error $? "regen_hotkey" + + ohai "Test wallet regeneration completed." + + else + echo "Enter your COLDKEY seed (NOT recommended in plaintext, but for example only):" + read -r user_cold_seed + + echo "Enter your HOTKEY seed:" + read -r user_hot_seed + + ohai "Regenerating your custom coldkey..." + btcli wallet regen_coldkey --name "default" --seed "$user_cold_seed" --overwrite + exit_on_error $? "regen_coldkey" + + ohai "Regenerating your custom hotkey..." + btcli wallet regen_hotkey --name "default" --seed "$user_hot_seed" --overwrite + exit_on_error $? "regen_hotkey" + + ohai "Custom wallet regeneration completed." + fi + else - echo "Invalid port range format. Please use the format: start-end (e.g., 2000-5000)" - exit 1 + ohai "Skipping wallet regeneration in manual mode." fi + fi } -# Do install. +################################################################################ +# MAIN INSTALL +################################################################################ OS="$(uname)" if [[ "$OS" == "Linux" ]]; then - which -s apt - if [[ $? == 0 ]] ; then - abort "This linux based install requires apt. To run with other distros (centos, arch, etc), you will need to manually install the requirements" + # Verify if apt is installed + if ! command -v apt >/dev/null 2>&1; then + abort "This Linux-based install requires apt. For other distros, install requirements manually." fi + echo """ ░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓███████▓▒░ ░▒▓████████▓▒░ @@ -251,51 +446,66 @@ if [[ "$OS" == "Linux" ]]; then - Bittensor; Mining a new element. """ - ohai "This script will install:" - echo "git" - echo "curl" - echo "cmake" - echo "build-essential" - echo "python3" - echo "python3-pip" - echo "subtensor" - echo "bittensor" - echo "docker" - echo "nvidia docker support" - echo "pm2" - echo "compute-subnet" - echo "hashcat" - echo "nvidia drivers and cuda toolkit" - echo "ufw" - - wait_for_user + if [[ "$AUTOMATED" == "true" ]]; then + ohai "Running in automated mode. Skipping interactive messages." + else + ohai "This script will install:" + echo "git" + echo "curl" + echo "cmake" + echo "build-essential" + echo "python3" + echo "python3-pip" + echo "subtensor" + echo "bittensor" + echo "docker" + echo "nvidia docker support" + echo "pm2" + echo "compute-subnet" + echo "hashcat" + echo "nvidia drivers and cuda toolkit" + echo "ufw" + + wait_for_user + fi linux_install_pre - linux_install_subtensor + + # Step 1: Install python, pip linux_install_python linux_update_pip - linux_install_bittensor + + # Step 2: Create and configure venv in /home/ubuntu/venv + linux_setup_venv + + # Step 3: Install Compute-Subnet and Bittensor inside the venv + linux_install_compute_subnet + + # PM2 (NodeJS) linux_install_pm2 + + # NVIDIA docker linux_install_nvidia_docker - linux_install_compute_subnet - linux_install_hashcat + + # CUDA (without removing existing drivers) linux_install_nvidia_cuda + + # UFW linux_install_ufw - linux_configure_ufw - ohai "Would you like to increase the ulimit? This will allow your miner to run for a longer time" - wait_for_user + # ulimit linux_increase_ulimit + # Solicitar WANDB key sólo en modo manual + if [[ "$AUTOMATED" == "false" ]]; then + ohai "Enter your wandb api key..." + ask_user_for_wandb_key + fi + + inject_wandb_env + echo "" echo "" - echo "######################################################################" - echo "## ##" - echo "## BITTENSOR SN27 SETUP ##" - echo "## ##" - echo "######################################################################" echo "" echo "" - -elif [[ "$OS" == "Darwin" ]]; then echo """ ██████╗░██╗████████╗████████╗███████╗███╗░░██╗░██████╗░█████╗░██████╗░ @@ -307,70 +517,24 @@ elif [[ "$OS" == "Darwin" ]]; then - Mining a new element. """ - ohai "This script will install:" - echo "xcode" - echo "homebrew" - echo "git" - echo "cmake" - echo "python3" - echo "python3-pip" - echo "bittensor" - - wait_for_user - mac_install_brew - mac_install_cmake - mac_install_python - mac_update_pip - mac_install_bittensor - echo "" - echo "" echo "######################################################################" echo "## ##" echo "## BITTENSOR SETUP ##" echo "## ##" echo "######################################################################" -else - abort "Bittensor is only supported on macOS and Linux" -fi -# Use the shell's audible bell. -if [[ -t 1 ]]; then -printf "\a" +elif [[ "$OS" == "Darwin" ]]; then + abort "macOS installation is not implemented in this auto script." +else + abort "Bittensor is only supported on macOS and Linux" fi +# Final messages echo "" +echo "Installation complete. Please reboot your machine for the changes to take effect:" +echo " sudo reboot" + echo "" -ohai "Welcome. Installation complete. Please reboot your machine for the changes to take effect:" -echo " $ sudo reboot" -echo "" -echo "- 1. Create a wallet pair" -echo " $ btcli w new_coldkey (for holding funds)" -echo " $ btcli w new_hotkey (for running miners)" -echo "" -echo "- 2. To run a miner on the Compute Subnetwork (SN27) you must first create a wallet pair and register to SN27. Visit ${tty_underline}https://docs.neuralinternet.ai/products/subnet-27-compute/bittensor-compute-subnet-miner-setup${tty_reset} for Instructions " -echo " pm2 start ./neurons/miner.py --name MINER --interpreter python3 -- --netuid 27 --subtensor.network local --wallet.name COLDKEYNAME --wallet.hotkey HOTKEYNAME --axon.port XXXX --logging.debug --miner.blacklist.force_validator_permit --auto_update yes " -echo "" -ohai "Extras:" -echo "" -echo "- Check your tao balance: " -echo " $ btcli wallet overview" -echo "" -echo "- Stake to your miners:" -echo " $ btcli stake add" -echo " $ btcli stake remove" -echo "" -echo "- Create/list/register wallets" -echo " $ btcli w new_coldkey" -echo " $ btcli w new_hotkey" -echo " $ btcli s list or $ btcli w list" -echo " $ btcli s register --subtensor.network finney --netuid 27" -echo "" -echo "- Use the Python API" -echo " $ python3" -echo " >> import bittensor" -echo "" -echo "- Join the discussion: " -echo " ${tty_underline}https://discord.gg/3rUr6EcvbB${tty_reset}" -echo "" -ohai "Installation complete. Please reboot your machine for the changes to take effect:" -echo " $ sudo reboot" +echo "After reboot, you can create a wallet pair and run your miner on SN27." +echo "See docs: https://docs.neuralinternet.ai/products/subnet-27-compute/bittensor-compute-subnet-miner-setup" +echo "Done." From 3d951b62833d67f3845c394b7d6fbcd708ba3987 Mon Sep 17 00:00:00 2001 From: David Maldonado Date: Mon, 27 Jan 2025 12:37:42 -0500 Subject: [PATCH 2/8] feat: problem with port range and open ssh --- Installation Script/install_sn27.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Installation Script/install_sn27.sh b/Installation Script/install_sn27.sh index 418e49a7..0248a9cc 100644 --- a/Installation Script/install_sn27.sh +++ b/Installation Script/install_sn27.sh @@ -304,18 +304,21 @@ linux_install_nvidia_cuda() { linux_configure_ufw() { sudo apt-get update && sudo apt-get install -y ufw + # Always allow port 22 for SSH first + ohai "Allowing SSH (port 22) through UFW..." + sudo ufw allow 22/tcp + if [[ "$AUTOMATED" == "true" ]]; then local default_range="2000-5000" ohai "AUTOMATED mode: enabling UFW for port range $default_range" sudo ufw allow "${default_range}/tcp" sudo ufw enable - ohai "UFW configured automatically for port range $default_range" - + ohai "UFW configured automatically for port range $default_range (and SSH is open)." else echo "Please enter the port range for UFW (e.g., 2000-5000):" read -p "Enter port range (start-end): " port_range - # Verificar formato "start-end" + # Validate "start-end" format if [[ "$port_range" =~ ^[0-9]+-[0-9]+$ ]]; then start_port=$(echo "$port_range" | cut -d'-' -f1) end_port=$(echo "$port_range" | cut -d'-' -f2) @@ -324,7 +327,7 @@ linux_configure_ufw() { ohai "Enabling UFW for port range $start_port-$end_port" sudo ufw allow "${start_port}:${end_port}/tcp" sudo ufw enable - ohai "UFW configured successfully with port range $port_range" + ohai "UFW configured successfully with port range $port_range (SSH is also open)." else echo "Invalid port range. The start port should be less than the end port." exit 1 @@ -336,6 +339,7 @@ linux_configure_ufw() { fi } + ################################################################################ # ULIMIT (CONFIGURABLE) ################################################################################ @@ -490,7 +494,7 @@ if [[ "$OS" == "Linux" ]]; then linux_install_nvidia_cuda # UFW - linux_install_ufw + linux_configure_ufw # ulimit linux_increase_ulimit From a8502d14582fa25bb94c781fed8053678783fe95 Mon Sep 17 00:00:00 2001 From: David Maldonado Date: Tue, 28 Jan 2025 15:53:33 -0500 Subject: [PATCH 3/8] fix: spanish comments, unused functions --- Installation Script/install_sn27.sh | 78 +++-------------------------- 1 file changed, 8 insertions(+), 70 deletions(-) diff --git a/Installation Script/install_sn27.sh b/Installation Script/install_sn27.sh index 0248a9cc..812de5fe 100644 --- a/Installation Script/install_sn27.sh +++ b/Installation Script/install_sn27.sh @@ -39,9 +39,6 @@ fi WANDB_ENV="${WANDB_KEY:-}" -COLDKEY_SEED="${COLDKEY_SEED:-}" - -HOTKEY_SEED="${HOTKEY_SEED:-}" ask_user_for_wandb_key() { read -rp "Enter WANDB_API_KEY (leave blank if none): " WANDB_ENV } @@ -111,6 +108,12 @@ linux_install_pre() { sudo apt-get update sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin exit_on_error $? "docker-installation" + + # 4. Add the 'ubuntu' user to the 'docker' group, so they can run Docker without sudo + sudo usermod -aG docker ubuntu + + ohai "Docker installation complete. 'ubuntu' user added to 'docker' group." + ohai "IMPORTANT: A new shell session (or reboot) is required for 'ubuntu' to see the new group membership." } ################################################################################ @@ -360,72 +363,6 @@ linux_increase_ulimit(){ fi } -regen_bittensor_wallet() { - if [[ "$AUTOMATED" == "true" ]]; then - ohai "Running wallet regeneration in AUTOMATED mode." - - if [[ -z "$COLDKEY_SEED" || -z "$HOTKEY_SEED" ]]; then - ohai "No COLDKEY_SEED/HOTKEY_SEED found in environment. Skipping wallet regen." - return - else - ohai "Regenerating coldkey with COLDKEY_SEED from env..." - btcli wallet regen_coldkey --name "default_cold" --mnemonic $COLDKEY_SEED - exit_on_error $? "regen_coldkey" - - ohai "Regenerating hotkey with HOTKEY_SEED from env..." - btcli wallet regen_hotkey --name "default_hot" --mnemonic $HOTKEY_SEED - exit_on_error $? "regen_hotkey" - - ohai "Wallet regeneration completed in AUTOMATED mode." - fi - - else - ohai "Do you want to regenerate (create) a Bittensor wallet? [y/N]" - read -r wallet_choice - wallet_choice="${wallet_choice,,}" # a minúsculas - - if [[ "$wallet_choice" == "y" || "$wallet_choice" == "yes" ]]; then - echo "Do you want to use test seeds or enter your own? [test/custom]" - read -r seed_choice - seed_choice="${seed_choice,,}" - - if [[ "$seed_choice" == "test" ]]; then - local cold_test_seed="example_cold_seed_for_testing_only" - local hot_test_seed="example_hot_seed_for_testing_only" - - ohai "Regenerating coldkey with test seed..." - btcli wallet regen_coldkey --name "default" --seed "$cold_test_seed" --overwrite - exit_on_error $? "regen_coldkey" - - ohai "Regenerating hotkey with test seed..." - btcli wallet regen_hotkey --name "default" --seed "$hot_test_seed" --overwrite - exit_on_error $? "regen_hotkey" - - ohai "Test wallet regeneration completed." - - else - echo "Enter your COLDKEY seed (NOT recommended in plaintext, but for example only):" - read -r user_cold_seed - - echo "Enter your HOTKEY seed:" - read -r user_hot_seed - - ohai "Regenerating your custom coldkey..." - btcli wallet regen_coldkey --name "default" --seed "$user_cold_seed" --overwrite - exit_on_error $? "regen_coldkey" - - ohai "Regenerating your custom hotkey..." - btcli wallet regen_hotkey --name "default" --seed "$user_hot_seed" --overwrite - exit_on_error $? "regen_hotkey" - - ohai "Custom wallet regeneration completed." - fi - - else - ohai "Skipping wallet regeneration in manual mode." - fi - fi -} ################################################################################ # MAIN INSTALL @@ -498,7 +435,8 @@ if [[ "$OS" == "Linux" ]]; then # ulimit linux_increase_ulimit - # Solicitar WANDB key sólo en modo manual + + #wandb_key if [[ "$AUTOMATED" == "false" ]]; then ohai "Enter your wandb api key..." ask_user_for_wandb_key From 43f47b8554a80afe30f672a2799e81a0e203205f Mon Sep 17 00:00:00 2001 From: David Maldonado Date: Thu, 30 Jan 2025 15:05:32 -0500 Subject: [PATCH 4/8] fix: allow ports for ssh --- Installation Script/install_sn27.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Installation Script/install_sn27.sh b/Installation Script/install_sn27.sh index 812de5fe..cf10065a 100644 --- a/Installation Script/install_sn27.sh +++ b/Installation Script/install_sn27.sh @@ -307,7 +307,6 @@ linux_install_nvidia_cuda() { linux_configure_ufw() { sudo apt-get update && sudo apt-get install -y ufw - # Always allow port 22 for SSH first ohai "Allowing SSH (port 22) through UFW..." sudo ufw allow 22/tcp @@ -315,13 +314,15 @@ linux_configure_ufw() { local default_range="2000-5000" ohai "AUTOMATED mode: enabling UFW for port range $default_range" sudo ufw allow "${default_range}/tcp" + ohai "Opening ports 8091 and 4444 for verifiers..." + sudo ufw allow 8091/tcp + sudo ufw allow 4444/tcp sudo ufw enable - ohai "UFW configured automatically for port range $default_range (and SSH is open)." + ohai "UFW configured automatically for port range $default_range (SSH is open, plus 8091 & 4444)." else echo "Please enter the port range for UFW (e.g., 2000-5000):" read -p "Enter port range (start-end): " port_range - # Validate "start-end" format if [[ "$port_range" =~ ^[0-9]+-[0-9]+$ ]]; then start_port=$(echo "$port_range" | cut -d'-' -f1) end_port=$(echo "$port_range" | cut -d'-' -f2) @@ -329,8 +330,11 @@ linux_configure_ufw() { if [[ $start_port -lt $end_port ]]; then ohai "Enabling UFW for port range $start_port-$end_port" sudo ufw allow "${start_port}:${end_port}/tcp" + ohai "Opening ports 8091 and 4444 for verifiers..." + sudo ufw allow 8091/tcp + sudo ufw allow 4444/tcp sudo ufw enable - ohai "UFW configured successfully with port range $port_range (SSH is also open)." + ohai "UFW configured successfully with port range $port_range (SSH is open, plus 8091 & 4444)." else echo "Invalid port range. The start port should be less than the end port." exit 1 @@ -343,6 +347,7 @@ linux_configure_ufw() { } + ################################################################################ # ULIMIT (CONFIGURABLE) ################################################################################ From cf96dae6367455ebbc1c2d32b855d20eb0b86594 Mon Sep 17 00:00:00 2001 From: David Maldonado Date: Thu, 30 Jan 2025 15:06:26 -0500 Subject: [PATCH 5/8] feat: new documentation install_script --- .../SN27 Installer Instructions.md | 214 +++++++++++++----- 1 file changed, 159 insertions(+), 55 deletions(-) diff --git a/Installation Script/SN27 Installer Instructions.md b/Installation Script/SN27 Installer Instructions.md index 0dc45bd1..ed690ab2 100644 --- a/Installation Script/SN27 Installer Instructions.md +++ b/Installation Script/SN27 Installer Instructions.md @@ -1,78 +1,182 @@ -# Bittensor/Compute Subnet Installer Script -This repository contains an installation script for setting up a Bittensor miner with the necessary dependencies and configurations for SN27 (Subnet 27) of the Bittensor network. This installation process requires Ubuntu 22.04. You are limited to one external IP per UID. There is automatic blacklisting in place if validators detect anomalous behavior. - - -## Features - -- Installs Bittensor and its dependencies -- Installs Docker for containerization -- Installs NVIDIA docker support for optimized GPU functionality -- Installs Subtensor and Starts a Lite Node on Mainnet -- Installs PM2 for process management -- Clones and installs the Compute-Subnet repository and its dependencies -- Starts the Docker service within Compute Subnet -- Installs Hashcat for computational tasks -- Installs NVIDIA drivers and CUDA toolkit for GPU functionality -- Installs UFW and configures ports for miners -- Provides a convenient one-line command for easy installation +# Bittensor and Compute-Subnet Setup Guide + +## Overview +This guide provides comprehensive instructions for setting up Bittensor and Compute-Subnet on a Linux system. Follow these steps to prepare your machine for mining and earning rewards. + +## Prerequisites + +### Required Items +- **Weights & Biases (WANDB) API Key** + - Generate from WANDB Account Settings + - Required for logging mining statistics + +- **Bittensor Wallets** + - Coldkey and Hotkey required + - Must be registered on Bittensor network + - Can be created using `btcli new_coldkey` and `btcli new_hotkey` + +- **GPU Drivers** + - Ubuntu 22.04: Automatic NVIDIA driver installation + - Other distributions: Manual CUDA driver installation required + - Verify installation with `nvidia-smi` and `nvcc --version` + +## CUDA Installation +Visit NVIDIA's official CUDA download page to get the latest version: +https://developer.nvidia.com/cuda-downloads + +For Ubuntu 22.04 (update version numbers as needed): + +1. Download CUDA repository package: +```bash +wget https://developer.download.nvidia.com/compute/cuda/12.3.1/local_installers/cuda-repo-ubuntu2204-12-3-local_12.3.1-545.23.08-1_amd64.deb +``` -## Usage +2. Install repository package: +```bash +sudo dpkg -i cuda-repo-ubuntu2204-12-3-local_12.3.1-545.23.08-1_amd64.deb +``` -This installation process requires Ubuntu 22.04. +3. Copy keyring: +```bash +sudo cp /var/cuda-repo-ubuntu2204-12-3-local/cuda-*-keyring.gpg /usr/share/keyrings/ +``` -Use a Virtual Environment +4. Update and install CUDA: +```bash +sudo apt-get update +sudo apt-get -y install cuda-toolkit-12-3 +sudo apt-get -y install -y cuda-drivers +``` -When working with Bittensor miners across various Subnets, it's highly recommended to use a virtual environment (venv) to isolate the dependencies and avoid potential conflicts. Each subnet may have different requirements, and using a separate virtual environment ensures that the dependencies are managed independently. +5. Set up environment variables: +```bash +export CUDA_VERSION=cuda-12.3 +export PATH=$PATH:/usr/local/$CUDA_VERSION/bin +export LD_LIBRARY_PATH=/usr/local/$CUDA_VERSION/lib64 +``` -To create and activate a virtual environment, follow these steps: +6. Add to bashrc: +```bash +echo "">>~/.bashrc +echo "PATH=$PATH">>~/.bashrc +echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH">>~/.bashrc +source ~/.bashrc +``` -1. Open a terminal and navigate to the directory where you want to create the virtual environment. +7. Reboot system: +```bash +sudo reboot +``` -2. Run the following command to create a new virtual environment: +### Verify CUDA Installation +Run `nvidia-smi`. Expected output should look like: ``` -python3 -m venv myenv ++---------------------------------------------------------------------------------------+ +| NVIDIA-SMI 545.29.06 Driver Version: 545.29.06 CUDA Version: 12.3 | +|-----------------------------------------+----------------------+----------------------+ +| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | +| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | +| | | MIG M. | +|=========================================+======================+======================| +| 0 NVIDIA RTX Off | 00000000:05:00.0 Off | Off | +| 30% 34C P0 70W / 300W | 400MiB / 4914000MiB | 4% Default | +| | | N/A | ++-----------------------------------------+----------------------+----------------------+ ``` -Replace `myenv` with your desired name for the virtual environment. - -3. Activate the virtual environment: -- For Linux or macOS: - ``` - source myenv/bin/activate - ``` -- For Windows: - ``` - myenv\Scripts\activate - ``` - -4. Once the virtual environment is activated, you'll see the name of the environment in your terminal prompt, indicating that you're now working within the isolated environment. - -5. Proceed with installing the required dependencies and running the Bittensor miner specific to the Subnet you're working on. - -6. To deactivate the virtual environment when you're done, simply run: +Run `nvcc --version`. Expected output: ``` -deactivate +nvcc: NVIDIA (R) Cuda compiler driver +Copyright (c) 2005-2023 NVIDIA Corporation +Built on Fri_Nov__3_17:16:49_PDT_2023 +Cuda compilation tools, release 12.3, V12.3.103 +Build cuda_12.3.r12.3/compiler.33492891_0 ``` -Using a virtual environment ensures that the dependencies and requirements are isolated and avoids potential conflicts. -Please remember to activate the appropriate virtual environment when you switch between Subnets or working on a different miner/project. +## Bittensor Installation -To install Bittensor with SN27 dependencies, simply run the following command in your terminal: +### Step 1: Download and Prepare Installer +```bash +curl -sL https://raw.githubusercontent.com/neuralinternet/compute-subnet/main/Installation%20Script/install_sn27.sh + -o SN27_installer.sh +chmod +x SN27_installer.sh ``` -/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/cisterciansis/Bittensor-Compute-Subnet-Installer-Script/main/install_sn27.sh)" + +### Step 2: Run Installation Script +```bash +./SN27_installer.sh ``` -The script will guide you through the installation process and set up the necessary components for running a Bittensor miner on SN27. -Please note that this script is designed for Linux systems with the apt package manager. If you're using a different Linux distribution or package manager, you may need to modify the script accordingly. +The installer will: +- Set up Docker with NVIDIA support +- Configure PM2 and NodeJS +- Create Python 3.10 virtual environment +- Clone and set up Compute-Subnet repository +- Install Bittensor dependencies + +## Post-Installation Verification -## Disclaimer +### Enter Virtual Environment +```bash +source /home/ubuntu/venv/bin/activate +``` -This script is provided as-is and without warranty. Use it at your own risk. Make sure to review the script and understand its actions before running it on your system. +### Docker Verification +```bash +docker --version +``` -## Contributions +### Bittensor CLI Verification +```bash +btcli --version +``` -Contributions to improve the script or add support for other platforms are welcome! Please feel free to open issues or submit pull requests. +### Directory Check +```bash +cd /home/ubuntu/Compute-Subnet +ls +``` -## License +## Running a Miner + +### Basic Miner Command +```bash +cd /home/ubuntu/Compute-Subnet +pm2 start ./neurons/miner.py --name MINER --interpreter python3 -- \ + --netuid 15 \ + --subtensor.network test \ + --wallet.name default \ + --wallet.hotkey default \ + --axon.port 8091 \ + --logging.debug \ + --miner.blacklist.force_validator_permit \ + --auto_update yes +``` -This script is released under the [MIT License](https://opensource.org/licenses/MIT). +## Troubleshooting + +### Common Issues and Solutions +1. **Missing WANDB Key** + - Edit `/home/ubuntu/Compute-Subnet/.env` + - Add your WANDB API key + +2. **Unregistered Wallet** + - Register your coldkey on Bittensor network first + - Use `btcli register` command + +3. **Docker Permissions** + ```bash + sudo usermod -aG docker $USER + ``` + Requires system relogin + +4. **Driver Issues** + - Manual installation required for non-Ubuntu 22.04 systems + - Verify with `nvidia-smi` + - Follow CUDA installation steps above if needed + +## Additional Resources +- [Weights & Biases Documentation](https://docs.wandb.ai/) +- [Bittensor Documentation](https://docs.bittensor.com/) +- [Compute-Subnet Documentation](https://docs.neuralinternet.ai) +- [NVIDIA CUDA Downloads](https://developer.nvidia.com/cuda-downloads) \ No newline at end of file From d973f8cc6aaa28d2289b3893bb867b41b846c636 Mon Sep 17 00:00:00 2001 From: David Maldonado Date: Thu, 30 Jan 2025 15:41:25 -0500 Subject: [PATCH 6/8] fix: install script and readme --- .../installer/README.md | 7 ++++++- {Installation Script => scripts/installer}/install_sn27.sh | 0 2 files changed, 6 insertions(+), 1 deletion(-) rename Installation Script/SN27 Installer Instructions.md => scripts/installer/README.md (98%) rename {Installation Script => scripts/installer}/install_sn27.sh (100%) diff --git a/Installation Script/SN27 Installer Instructions.md b/scripts/installer/README.md similarity index 98% rename from Installation Script/SN27 Installer Instructions.md rename to scripts/installer/README.md index ed690ab2..4e263b16 100644 --- a/Installation Script/SN27 Installer Instructions.md +++ b/scripts/installer/README.md @@ -97,7 +97,7 @@ Build cuda_12.3.r12.3/compiler.33492891_0 ### Step 1: Download and Prepare Installer ```bash -curl -sL https://raw.githubusercontent.com/neuralinternet/compute-subnet/main/Installation%20Script/install_sn27.sh +curl -sL https://raw.githubusercontent.com/neuralinternet/compute-subnet/main/scripts/installer/install_sn27.sh -o SN27_installer.sh chmod +x SN27_installer.sh ``` @@ -116,6 +116,11 @@ The installer will: ## Post-Installation Verification +### Reboot your machine +```bash +sudo reboot +``` + ### Enter Virtual Environment ```bash source /home/ubuntu/venv/bin/activate diff --git a/Installation Script/install_sn27.sh b/scripts/installer/install_sn27.sh similarity index 100% rename from Installation Script/install_sn27.sh rename to scripts/installer/install_sn27.sh From a9cad35cb0bd7844147b83a3165a3a22e02b76f8 Mon Sep 17 00:00:00 2001 From: David Maldonado Date: Thu, 30 Jan 2025 19:42:02 -0500 Subject: [PATCH 7/8] fix: changes on ufw automatic open ports --- scripts/installer/install_sn27.sh | 42 ++++++------------------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/scripts/installer/install_sn27.sh b/scripts/installer/install_sn27.sh index cf10065a..b0501ffe 100644 --- a/scripts/installer/install_sn27.sh +++ b/scripts/installer/install_sn27.sh @@ -310,40 +310,14 @@ linux_configure_ufw() { ohai "Allowing SSH (port 22) through UFW..." sudo ufw allow 22/tcp - if [[ "$AUTOMATED" == "true" ]]; then - local default_range="2000-5000" - ohai "AUTOMATED mode: enabling UFW for port range $default_range" - sudo ufw allow "${default_range}/tcp" - ohai "Opening ports 8091 and 4444 for verifiers..." - sudo ufw allow 8091/tcp - sudo ufw allow 4444/tcp - sudo ufw enable - ohai "UFW configured automatically for port range $default_range (SSH is open, plus 8091 & 4444)." - else - echo "Please enter the port range for UFW (e.g., 2000-5000):" - read -p "Enter port range (start-end): " port_range - - if [[ "$port_range" =~ ^[0-9]+-[0-9]+$ ]]; then - start_port=$(echo "$port_range" | cut -d'-' -f1) - end_port=$(echo "$port_range" | cut -d'-' -f2) - - if [[ $start_port -lt $end_port ]]; then - ohai "Enabling UFW for port range $start_port-$end_port" - sudo ufw allow "${start_port}:${end_port}/tcp" - ohai "Opening ports 8091 and 4444 for verifiers..." - sudo ufw allow 8091/tcp - sudo ufw allow 4444/tcp - sudo ufw enable - ohai "UFW configured successfully with port range $port_range (SSH is open, plus 8091 & 4444)." - else - echo "Invalid port range. The start port should be less than the end port." - exit 1 - fi - else - echo "Invalid port range format. Please use the format: start-end (e.g., 2000-5000)" - exit 1 - fi - fi + ohai "Opening ports 8091 and 4444 for verifiers..." + sudo ufw allow 8091/tcp + sudo ufw allow 4444/tcp + + ohai "Enabling UFW..." + sudo ufw --force enable + + ohai "UFW configured. Open ports: 22 (SSH), 8091, 4444." } From 0f1512916e09773e0d00fb9e3b02b831bdf36278 Mon Sep 17 00:00:00 2001 From: David Maldonado Date: Thu, 30 Jan 2025 21:38:38 -0500 Subject: [PATCH 8/8] fix: automated mode on ufw --- scripts/installer/install_sn27.sh | 32 +++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/scripts/installer/install_sn27.sh b/scripts/installer/install_sn27.sh index b0501ffe..6c379f17 100644 --- a/scripts/installer/install_sn27.sh +++ b/scripts/installer/install_sn27.sh @@ -310,18 +310,42 @@ linux_configure_ufw() { ohai "Allowing SSH (port 22) through UFW..." sudo ufw allow 22/tcp - ohai "Opening ports 8091 and 4444 for verifiers..." - sudo ufw allow 8091/tcp - sudo ufw allow 4444/tcp + # If AUTOMATED mode is true, skip user input and use defaults: + if [[ "$AUTOMATED" == "true" ]]; then + port_4444=4444 + port_8091=8091 + + ohai "AUTOMATED mode detected." + ohai "Opening port $port_4444 (validators/dashboard) and port $port_8091 (Axon)..." + sudo ufw allow "${port_4444}/tcp" + sudo ufw allow "${port_8091}/tcp" + else + # Otherwise, ask the user which ports to open: + echo "Enter the port number for validators/dashboard (Default: 4444)." + echo " 4444 is used by validators and dashboard to allocate the machine via SSH." + read -p "Port for validators/dashboard [4444]: " port_4444 + port_4444="${port_4444:-4444}" # If empty, default to 4444 + + echo "Enter the port number for Axon (Default: 8091)." + echo " 8091 is the typical port for Axon." + read -p "Port for Axon [8091]: " port_8091 + port_8091="${port_8091:-8091}" # If empty, default to 8091 + + ohai "Opening port $port_4444 (validators/dashboard) and port $port_8091 (Axon)..." + sudo ufw allow "${port_4444}/tcp" + sudo ufw allow "${port_8091}/tcp" + fi ohai "Enabling UFW..." sudo ufw --force enable - ohai "UFW configured. Open ports: 22 (SSH), 8091, 4444." + ohai "UFW configured. Open ports: 22 (SSH), $port_4444, $port_8091." } + + ################################################################################ # ULIMIT (CONFIGURABLE) ################################################################################