laconic-network-bootstrap/scripts/lib.sh

43 lines
1.0 KiB
Bash

function error_exit() {
echo "Error: $1"
exit 1
}
function assert_defined() {
local variable_name=$1
if [[ ! ${!variable_name} ]]; then
error_exit "$variable_name is not defined"
fi
}
network_config_file=./network.cfg
if [[ ! -f ${network_config_file} ]]; then
error_exit "$network_config_file does not exist"
fi
source ${network_config_file}
assert_defined "machine_domain"
assert_defined "node_count"
assert_defined "ssh_user"
assert_defined "node_network_dir"
assert_defined "chain_id"
assert_defined "p2p_port"
# Hack until we fix PATH for remote sessions
so_command=/home/laconic/bin/laconic-so
# run_on_all_nodes(machine_name_prefix, command_to_run)
function run_on_all_nodes() {
local machine_name_prefix=$1
local command_to_run=$2
for (( i=1 ; i<=$node_count ; i++ ));
do
local machine_name=${machine_name_prefix}-${i}.${machine_domain}
echo "${machine_name}:"
echo "Running: ${command_to_run}"
ssh ${ssh_user}@${machine_name} ${command_to_run}
done
}