2024-02-26 18:29:35 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-03-05 09:39:33 +00:00
|
|
|
set -of pipefail
|
2024-02-26 18:29:35 +00:00
|
|
|
|
|
|
|
GRN='\033[0;32m'
|
|
|
|
BLD='\033[1m'
|
|
|
|
RST='\033[0m'
|
|
|
|
|
2024-03-15 11:06:59 +00:00
|
|
|
DOMAIN='status.im'
|
2024-02-26 18:29:35 +00:00
|
|
|
|
|
|
|
function fleets() {
|
|
|
|
grep -oP '^\[\K[^]]+' ansible/inventory/test
|
|
|
|
}
|
|
|
|
|
|
|
|
function hosts() {
|
|
|
|
awk "
|
|
|
|
/^\[${1}\]$/{
|
|
|
|
while (\$0 != \"\") {
|
|
|
|
getline
|
|
|
|
print(\$1)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
" ansible/inventory/test
|
|
|
|
}
|
|
|
|
|
|
|
|
function ssh_command() {
|
|
|
|
echo -e "${GRN}${BLD}${1}${RST}"
|
|
|
|
ssh -o StrictHostKeyChecking=accept-new "${1}.${DOMAIN}" "${2}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function usage() {
|
|
|
|
echo "
|
|
|
|
Usage: $0 [FLEET] <COMMAND>
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
$0 nimbus.sepolia 'systemctl start build-beacon-node-sepolia-stable'
|
|
|
|
|
|
|
|
echo linux-01.ih-eu-mda1.nimbus.sepolia | $0 'systemctl start build-beacon-node-sepolia-stable'
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ "${#}" -eq 0 ]]; then
|
|
|
|
usage
|
|
|
|
echo -e "Available fleets:\n"
|
|
|
|
fleets
|
|
|
|
exit
|
|
|
|
elif [[ "${#}" -eq 1 ]]; then
|
|
|
|
# Get hostnames from stdin.
|
|
|
|
while IFS=$'\n' read -r FLEET_HOST; do
|
|
|
|
ssh_command "${FLEET_HOST}" "${1}"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# Get hostnames using fleet name.
|
|
|
|
for FLEET_HOST in $(hosts "${1}"); do
|
|
|
|
ssh_command "${FLEET_HOST}" "${2}"
|
|
|
|
done
|
|
|
|
fi
|