-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
executable file
·39 lines (29 loc) · 922 Bytes
/
script.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
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <number_of_nodes> <protocol_to_consensus>"
exit 1
fi
N=$1
docker network create --subnet=172.18.0.0/16 mynet
go mod tidy
go build -o cons
./cons 0 "$N" "172.18.0.2" #This is to generate the nodes in JSON File
docker build -t consensus:latest .
json_file="nodes_data.json"
# Use jq to iterate over the JSON array
count=$(jq length "$json_file")
echo "Total elements: $count"
for i in $(seq 0 $(($count - 1))); do
node_id=$(jq -r ".[$i].NodeID" "$json_file")
ip=$(jq -r ".[$i].IP" "$json_file")
trimmed_ip="${ip%%:*}"
echo "Original IP: $ip"
echo "Trimmed_ip: $trimmed_ip"
if [ "$node_id" -eq 0 ]; then
echo "Skipping execution for NodeID 0."
continue
fi
container_id=$(docker run --net mynet --ip $trimmed_ip -d -t consensus)
# shellcheck disable=SC2027
docker exec -d "$container_id" bash -c "./cons "$2" "$node_id" 0"
done