|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -# Inspect the Kurtosis enclave |
| 3 | +# Inspect the Kurtosis enclave and capture the output |
4 | 4 | output=$(kurtosis enclave inspect my-testnet)
|
5 | 5 |
|
6 |
| -# Extract relevant information |
7 |
| -services=$(echo "$output" | awk '/User Services/,/Search results:/ {if(NR>4) print $0}') |
| 6 | +# Check if the command succeeded |
| 7 | +if [[ $? -ne 0 ]]; then |
| 8 | + echo "Error: Failed to inspect the enclave 'my-testnet'." |
| 9 | + exit 1 |
| 10 | +fi |
8 | 11 |
|
9 |
| -# Prepare an array to hold service details |
10 |
| -declare -a service_details |
| 12 | +# Prepare an array to hold endpoint configurations |
| 13 | +declare -a endpoints |
11 | 14 |
|
12 |
| -# Loop through each service entry |
| 15 | +# Extract the "User Services" section from the output |
| 16 | +services_section=$(echo "$output" | awk '/User Services:/,0' | sed '1d') |
| 17 | + |
| 18 | +# Debugging: Output the services section for inspection |
| 19 | +echo "Services section extracted:" |
| 20 | +echo "$services_section" |
| 21 | + |
| 22 | +# Loop through each line in the services section |
13 | 23 | while IFS= read -r line; do
|
14 |
| - # Skip empty lines |
15 |
| - [[ -z "$line" ]] && continue |
| 24 | + # Skip empty or invalid lines |
| 25 | + [[ -z "$line" || "$line" =~ ^Search\ results: ]] && continue |
16 | 26 |
|
17 |
| - # Extract UUID, Name, and Ports |
| 27 | + # Debugging: Output each line being processed |
| 28 | + echo "Processing line: $line" |
| 29 | + |
| 30 | + # Extract UUID, Name, and Ports using awk |
18 | 31 | uuid=$(echo "$line" | awk '{print $1}')
|
19 | 32 | name=$(echo "$line" | awk '{print $2}')
|
20 |
| - ports=$(echo "$line" | awk '{for(i=3;i<=NF;i++) printf $i " "; print ""}' | sed 's/ *$//') # Join all remaining fields as ports |
| 33 | + ports=$(echo "$line" | awk '{for(i=3;i<=NF;i++) printf $i " "; print ""}' | sed 's/ *$//') |
| 34 | + |
| 35 | + # Debugging: Output the extracted UUID, Name, and Ports |
| 36 | + echo "UUID: $uuid" |
| 37 | + echo "Name: $name" |
| 38 | + echo "Ports: $ports" |
| 39 | + |
| 40 | + # Check if the service is related to an execution client (e.g., Geth, Lodestar, Prysm) |
| 41 | + if [[ "$name" == *"geth"* || "$name" == *"lodestar"* || "$name" == *"prysm"* ]]; then |
| 42 | + # Extract RPC and Metrics ports using regex |
| 43 | + rpc_port=$(echo "$ports" | grep -oP 'rpc: \K[0-9]+' | head -1) |
| 44 | + metrics_port=$(echo "$ports" | grep -oP 'metrics: \K[0-9]+' | head -1) |
| 45 | + |
| 46 | + # Debugging: Output the extracted RPC and Metrics ports |
| 47 | + echo "RPC Port: $rpc_port" |
| 48 | + echo "Metrics Port: $metrics_port" |
| 49 | + |
| 50 | + # Check if both RPC and Metrics ports are found |
| 51 | + if [[ -n "$rpc_port" && -n "$metrics_port" ]]; then |
| 52 | + # Construct the endpoint JSON object and add it to the array |
| 53 | + endpoints+=("{\"name\": \"$name\", \"executionUrl\": \"http://localhost:$rpc_port\", \"consensusUrl\": \"http://localhost:$metrics_port\"}") |
| 54 | + fi |
| 55 | + fi |
| 56 | +done <<< "$services_section" |
| 57 | + |
| 58 | +# Print the array in a usable format |
| 59 | +echo "Endpoints array:" |
| 60 | +for endpoint in "${endpoints[@]}"; do |
| 61 | + echo "$endpoint" |
| 62 | +done |
21 | 63 |
|
22 |
| - # Format the output for Assertor |
23 |
| - service_details+=("{\"uuid\": \"$uuid\", \"name\": \"$name\", \"ports\": \"$ports\"}") |
24 |
| -done <<< "$services" |
| 64 | +# If you want to return the array to be used later in the script: |
| 65 | +# You can access the array like this: |
| 66 | +# for endpoint in "${endpoints[@]}"; do |
| 67 | +# echo "$endpoint" |
| 68 | +# done |
25 | 69 |
|
26 |
| -# Print the extracted service details in JSON format for Assertor |
27 |
| -echo "[${service_details[*]}]" |
|
0 commit comments