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