/ .devnet / reinstall.sh
reinstall.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  #      rm -rf \$WORKSPACE
32  #      git clone https://github.com/ProvableHQ/snarkOS.git \$WORKSPACE
33        cd \$WORKSPACE
34        git pull # If we are switching branches, this will find the new branch
35        git checkout $BRANCH  # Checkout the specified branch
36        git pull origin $BRANCH
37      else
38        # The workspace directory doesn't exist, clone the repository
39        git clone https://github.com/ProvableHQ/snarkOS.git \$WORKSPACE
40        cd \$WORKSPACE
41        git checkout $BRANCH  # Checkout the specified branch
42      fi
43  
44      cargo install --path .
45      exit  # Exit root user
46  EOF
47  
48    # Check the exit status of the SSH command
49    if [ $? -eq 0 ]; then
50      echo "Installation on aws-n$NODE_ID completed successfully."
51    else
52      echo "Installation on aws-n$NODE_ID failed."
53    fi
54  }
55  
56  # Loop through aws-n nodes and run installations in parallel
57  for NODE_ID in $(seq 0 $(($NUM_INSTANCES - 1))); do
58    run_installation $NODE_ID $BRANCH &
59  done
60  
61  # Wait for all background jobs to finish
62  wait