2018-08-28 10:19:33 -07:00
|
|
|
# |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
|
|
|
|
#
|
|
|
|
|
2018-09-08 19:19:12 -07:00
|
|
|
netDir=$(
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
|
|
|
|
echo "$PWD"
|
|
|
|
)
|
|
|
|
netConfigDir="$netDir"/config
|
2019-11-08 21:18:21 -08:00
|
|
|
mkdir -p "$netConfigDir"
|
2018-08-28 10:19:33 -07:00
|
|
|
|
2019-10-17 14:44:45 -07:00
|
|
|
SOLANA_ROOT="$netDir"/..
|
2018-09-03 21:15:55 -07:00
|
|
|
# shellcheck source=scripts/configure-metrics.sh
|
2019-10-17 14:44:45 -07:00
|
|
|
source "$SOLANA_ROOT"/scripts/configure-metrics.sh
|
2018-09-03 21:15:55 -07:00
|
|
|
|
2018-08-29 08:01:52 -07:00
|
|
|
configFile="$netConfigDir/config"
|
2019-04-28 19:50:02 -07:00
|
|
|
geoipConfigFile="$netConfigDir/geoip.yml"
|
2018-08-28 10:19:33 -07:00
|
|
|
|
2018-09-04 22:21:58 -07:00
|
|
|
entrypointIp=
|
|
|
|
publicNetwork=
|
2018-09-03 21:15:55 -07:00
|
|
|
netBasename=
|
2018-08-28 10:19:33 -07:00
|
|
|
sshPrivateKey=
|
2019-07-09 15:45:46 -07:00
|
|
|
letsEncryptDomainName=
|
2019-04-01 15:54:41 -07:00
|
|
|
externalNodeSshKey=
|
2018-09-04 22:21:58 -07:00
|
|
|
sshOptions=()
|
2019-10-21 20:21:21 -07:00
|
|
|
validatorIpList=()
|
|
|
|
validatorIpListPrivate=()
|
|
|
|
validatorIpListZone=()
|
2018-12-09 09:42:09 -08:00
|
|
|
clientIpList=()
|
|
|
|
clientIpListPrivate=()
|
2019-04-28 19:50:02 -07:00
|
|
|
clientIpListZone=()
|
2019-02-21 15:35:26 -08:00
|
|
|
blockstreamerIpList=()
|
|
|
|
blockstreamerIpListPrivate=()
|
2019-04-28 19:50:02 -07:00
|
|
|
blockstreamerIpListZone=()
|
2018-08-28 10:19:33 -07:00
|
|
|
|
2018-09-03 21:15:55 -07:00
|
|
|
buildSshOptions() {
|
|
|
|
sshOptions=(
|
2019-04-19 17:46:14 -07:00
|
|
|
-o "ConnectTimeout=20"
|
2018-09-03 21:15:55 -07:00
|
|
|
-o "BatchMode=yes"
|
|
|
|
-o "StrictHostKeyChecking=no"
|
|
|
|
-o "UserKnownHostsFile=/dev/null"
|
2018-09-08 19:19:12 -07:00
|
|
|
-o "User=solana"
|
2019-12-03 15:53:12 -08:00
|
|
|
-o "IdentitiesOnly=yes"
|
2018-09-03 21:15:55 -07:00
|
|
|
-o "IdentityFile=$sshPrivateKey"
|
|
|
|
-o "LogLevel=ERROR"
|
|
|
|
)
|
2019-04-01 15:54:41 -07:00
|
|
|
|
|
|
|
[[ -z $externalNodeSshKey ]] || sshOptions+=(-o "IdentityFile=$externalNodeSshKey")
|
2018-09-03 21:15:55 -07:00
|
|
|
}
|
|
|
|
|
2018-08-28 10:19:33 -07:00
|
|
|
loadConfigFile() {
|
|
|
|
[[ -r $configFile ]] || usage "Config file unreadable: $configFile"
|
|
|
|
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
source "$configFile"
|
2018-09-04 22:21:58 -07:00
|
|
|
[[ -n "$publicNetwork" ]] || usage "Config file invalid, publicNetwork unspecified: $configFile"
|
|
|
|
[[ -n "$netBasename" ]] || usage "Config file invalid, netBasename unspecified: $configFile"
|
2018-08-28 10:19:33 -07:00
|
|
|
[[ -n $sshPrivateKey ]] || usage "Config file invalid, sshPrivateKey unspecified: $configFile"
|
2019-10-21 20:21:21 -07:00
|
|
|
[[ ${#validatorIpList[@]} -gt 0 ]] || usage "Config file invalid, validatorIpList unspecified: $configFile"
|
|
|
|
[[ ${#validatorIpListPrivate[@]} -gt 0 ]] || usage "Config file invalid, validatorIpListPrivate unspecified: $configFile"
|
|
|
|
[[ ${#validatorIpList[@]} -eq ${#validatorIpListPrivate[@]} ]] || usage "Config file invalid, validatorIpList/validatorIpListPrivate length mismatch: $configFile"
|
2018-12-09 09:42:09 -08:00
|
|
|
|
|
|
|
if $publicNetwork; then
|
2019-10-21 20:21:21 -07:00
|
|
|
entrypointIp=${validatorIpList[0]}
|
2018-12-09 09:42:09 -08:00
|
|
|
else
|
2019-10-21 20:21:21 -07:00
|
|
|
entrypointIp=${validatorIpListPrivate[0]}
|
2018-12-09 09:42:09 -08:00
|
|
|
fi
|
2018-08-28 10:19:33 -07:00
|
|
|
|
2018-09-03 21:15:55 -07:00
|
|
|
buildSshOptions
|
|
|
|
configureMetrics
|
2018-08-28 10:19:33 -07:00
|
|
|
}
|
2019-08-21 18:06:09 -07:00
|
|
|
|
|
|
|
# https://gist.github.com/cdown/1163649
|
|
|
|
urlencode() {
|
|
|
|
declare s="$1"
|
|
|
|
declare l=$((${#s} - 1))
|
|
|
|
for i in $(seq 0 $l); do
|
|
|
|
declare c="${s:$i:1}"
|
|
|
|
case $c in
|
|
|
|
[a-zA-Z0-9.~_-])
|
|
|
|
echo -n "$c"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf '%%%02X' "'$c"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-10-17 14:44:45 -07:00
|
|
|
SOLANA_CONFIG_DIR=$SOLANA_ROOT/config
|
|
|
|
# Clear the current cluster configuration
|
|
|
|
clear_config_dir() {
|
|
|
|
declare config_dir="$1"
|
2019-10-21 15:38:58 -07:00
|
|
|
|
2019-10-24 13:40:16 -07:00
|
|
|
_setup_secondary_mount
|
2019-10-21 15:38:58 -07:00
|
|
|
|
2019-10-17 14:44:45 -07:00
|
|
|
(
|
|
|
|
set -x
|
|
|
|
rm -rf "${config_dir:?}/" # <-- $i might be a symlink, rm the other side of it first
|
|
|
|
rm -rf "$config_dir"
|
|
|
|
mkdir -p "$config_dir"
|
|
|
|
)
|
2019-10-24 13:40:16 -07:00
|
|
|
|
|
|
|
_setup_secondary_mount
|
2019-10-17 14:44:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
SECONDARY_DISK_MOUNT_POINT=/mnt/extra-disk
|
2019-10-24 13:40:16 -07:00
|
|
|
_setup_secondary_mount() {
|
2019-10-17 14:44:45 -07:00
|
|
|
# If there is a secondary disk, symlink the config/ dir there
|
2019-10-21 17:00:17 -07:00
|
|
|
(
|
|
|
|
set -x
|
|
|
|
if [[ -d $SECONDARY_DISK_MOUNT_POINT ]] && \
|
|
|
|
[[ -w $SECONDARY_DISK_MOUNT_POINT ]]; then
|
|
|
|
mkdir -p $SECONDARY_DISK_MOUNT_POINT/config
|
|
|
|
rm -rf "$SOLANA_CONFIG_DIR"
|
|
|
|
ln -sfT $SECONDARY_DISK_MOUNT_POINT/config "$SOLANA_CONFIG_DIR"
|
|
|
|
fi
|
|
|
|
)
|
2019-10-17 14:44:45 -07:00
|
|
|
}
|