/ .devnet / install.sh
install.sh
 1  #!/bin/bash
 2  
 3  # Prompt the user for the branch to install (default is "mainnet")
 4  read -p "Enter the branch to install (default: mainnet): " BRANCH
 5  BRANCH=${BRANCH:-mainnet}
 6  
 7  # Determine the number of AWS EC2 instances by checking ~/.ssh/config
 8  NODE_ID=0
 9  while [ -n "$(grep "aws-n${NODE_ID}" ~/.ssh/config)" ]; do
10      NODE_ID=$((NODE_ID + 1))
11  done
12  
13  # Read the number of AWS EC2 instances to query from the user
14  read -p "Enter the number of AWS EC2 instances to query (default: $NODE_ID): " NUM_INSTANCES
15  NUM_INSTANCES="${NUM_INSTANCES:-$NODE_ID}"
16  
17  echo "Using $NUM_INSTANCES AWS EC2 instances for querying."
18  
19  # Define a function to run the installation on a node
20  run_installation() {
21    local NODE_ID=$1
22    local BRANCH=$2
23    # SSH into the node
24    ssh -o StrictHostKeyChecking=no aws-n$NODE_ID << EOF
25      # Commands to run on the remote instance
26      sudo -i  # Switch to root user
27      WORKSPACE=~/snarkOS
28  
29      if [ -d "\$WORKSPACE" ]; then
30        # The workspace directory exists, update the existing repository
31        cd \$WORKSPACE
32        git pull origin $BRANCH
33      else
34        # The workspace directory doesn't exist, clone the repository
35        git clone https://github.com/ProvableHQ/snarkOS.git \$WORKSPACE
36        cd \$WORKSPACE
37        git checkout $BRANCH  # Checkout the specified branch
38      fi
39  
40      sudo ./build_ubuntu.sh
41      exit  # Exit root user
42  EOF
43  
44    # Check the exit status of the SSH command
45    if [ $? -eq 0 ]; then
46      echo "Installation on aws-n$NODE_ID completed successfully."
47    else
48      echo "Installation on aws-n$NODE_ID failed."
49    fi
50  }
51  
52  # Loop through aws-n nodes and run installations in parallel
53  for NODE_ID in $(seq 0 $(($NUM_INSTANCES - 1))); do
54    run_installation $NODE_ID $BRANCH &
55  done
56  
57  # Wait for all background jobs to finish
58  wait