diff --git a/tools/scripts/storage-config.sh b/tools/scripts/storage-config.sh index c07b5c93..6e16bb4d 100644 --- a/tools/scripts/storage-config.sh +++ b/tools/scripts/storage-config.sh @@ -1,24 +1,27 @@ #!/usr/bin/env bash # Script for generating configuration files and network presets for # Logos Storage. - set -euo pipefail -# Valid networks -declare -A _networks -#_networks=([test]="Logos testnet" [dev]="Logos devnet") -_networks=([dev]="Logos devnet") - echoerr() { echo "[storage_config] $1" >&2 } -require() { - if ! command -v "$1" &> /dev/null; then - echoerr "Error: $1 is not installed" - exit 1 - fi -} +# Needs bash 4 or higher +if ((${BASH_VERSION:-0} < 4)); then + echoerr "Error: This script requires Bash 4 or higher." + exit 1 +fi + +# Needs jq +if ! command -v jq &> /dev/null; then + echoerr "Error: jq is not installed" + exit 1 +fi + +# Valid networks +declare -A _networks +_networks=([dev]="Logos devnet" [test]="Logos testnet") check_network() { local network=$1 @@ -37,12 +40,15 @@ raw_data() { mix_pool_json() { local network=$1 check_network "$network" - raw_data "$network" | jq 'map({ - "peerId": .peerId, - "mixPubKey": .mixPubKey, - "libp2pPubKey": .libp2pPubKey, - "multiAddr": "/ip4/\(.address)/tcp/\(.port)", - })' + raw_data "$network" | jq -c '{ + "version": 1, + "relays": map({ + "peerId": .peerId, + "mixPubKey": .mixPubKey, + "libp2pPubKey": .libp2pPubKey, + "multiAddr": "/ip4/\(.address)/tcp/\(.port)", + }) + }' } bootstrap_sprs() { @@ -67,7 +73,7 @@ full_config() { "network": "logos.${network}", "mix-enabled": true, "dht-mix-proxy": $(mix_proxy_sprs "$network"), - "mix-pool-json": $(mix_pool_json "$network"), + "mix-pool-json": $(mix_pool_json "$network" | jq -c '. | tostring') } EOF } @@ -98,8 +104,6 @@ EOF EOF } -require jq - usage() { cat < [network] @@ -110,7 +114,7 @@ Commands: raw_data Fetch raw storage-network data from fleets.logos.co mix_pool_json Generate mix pool JSON configuration bootstrap_sprs List bootstrap SPRs - mix_proxy_sprs List mix proxy SPRs (tcpSpr) + mix_proxy_sprs List mix proxy SPRs full_config Generate full node configuration JSON presets Generate network presets JSON for all networks @@ -124,7 +128,7 @@ Examples: EOF } -if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" || "$1" == "help" ]]; then +if [[ $# -eq 0 ]]; then usage exit 0 fi