solana/net/common.sh

73 lines
2.1 KiB
Bash
Raw Normal View History

# |source| this file
#
# Common utilities shared by other scripts in this directory
#
# The following directive disable complaints about unused variables in this
# file:
# shellcheck disable=2034
#
netDir=$(
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
echo "$PWD"
)
netConfigDir="$netDir"/config
netLogDir="$netDir"/log
mkdir -p "$netConfigDir" "$netLogDir"
2018-09-03 21:15:55 -07:00
# shellcheck source=scripts/configure-metrics.sh
source "$(dirname "${BASH_SOURCE[0]}")"/../scripts/configure-metrics.sh
configFile="$netConfigDir/config"
entrypointIp=
publicNetwork=
2018-09-03 21:15:55 -07:00
netBasename=
sshPrivateKey=
externalNodeSshKey=
sshOptions=()
fullnodeIpList=()
fullnodeIpListPrivate=()
clientIpList=()
clientIpListPrivate=()
blockstreamerIpList=()
blockstreamerIpListPrivate=()
2018-12-05 17:33:32 -08:00
leaderRotation=
2018-09-03 21:15:55 -07:00
buildSshOptions() {
sshOptions=(
-o "ConnectTimeout=20"
2018-09-03 21:15:55 -07:00
-o "BatchMode=yes"
-o "StrictHostKeyChecking=no"
-o "UserKnownHostsFile=/dev/null"
-o "User=solana"
2018-09-03 21:15:55 -07:00
-o "IdentityFile=$sshPrivateKey"
-o "LogLevel=ERROR"
)
[[ -z $externalNodeSshKey ]] || sshOptions+=(-o "IdentityFile=$externalNodeSshKey")
2018-09-03 21:15:55 -07:00
}
loadConfigFile() {
[[ -r $configFile ]] || usage "Config file unreadable: $configFile"
# shellcheck source=/dev/null
source "$configFile"
[[ -n "$publicNetwork" ]] || usage "Config file invalid, publicNetwork unspecified: $configFile"
[[ -n "$netBasename" ]] || usage "Config file invalid, netBasename unspecified: $configFile"
[[ -n $sshPrivateKey ]] || usage "Config file invalid, sshPrivateKey unspecified: $configFile"
2018-12-05 17:33:32 -08:00
[[ -n $leaderRotation ]] || usage "Config file invalid, leaderRotation unspecified: $configFile"
[[ ${#fullnodeIpList[@]} -gt 0 ]] || usage "Config file invalid, fullnodeIpList unspecified: $configFile"
[[ ${#fullnodeIpListPrivate[@]} -gt 0 ]] || usage "Config file invalid, fullnodeIpListPrivate unspecified: $configFile"
2019-01-16 09:38:29 -08:00
[[ ${#fullnodeIpList[@]} -eq ${#fullnodeIpListPrivate[@]} ]] || usage "Config file invalid, fullnodeIpList/fullnodeIpListPrivate length mismatch: $configFile"
if $publicNetwork; then
entrypointIp=${fullnodeIpList[0]}
else
entrypointIp=${fullnodeIpListPrivate[0]}
fi
2018-09-03 21:15:55 -07:00
buildSshOptions
configureMetrics
}