laconic-network-bootstrap/scripts/lib.sh
2024-07-08 06:22:16 -06:00

40 lines
965 B
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"
# 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
}