#!/usr/bin/env bash
# This script assumes that the keys used by publishers
# corresponds to the UNIQUE hostname of each monitored node

# Check parameters
[ $# -ne 1 ] && { echo "Usage: $0 [on|off]"; exit 1; }
if [ "$1" != "on" ]
then
    [ "$1" != "off" ] && { echo "Usage: $0 [on|off]"; exit 1; }
fi

# Load configuration
wai=$(dirname $(readlink -f "$0")) # Current script directory
source ${wai}/config.mk
source ${wai}/.clusterman.sh.conf

# Loop over names
for value in "${nodes[@]}"; do
    node=$(echo "$value"|cut -d "/" -f 1)
    ina260=$(echo "$value"|cut -d "/" -f 2)
    ip=$(clusterman node list -g $node)
    [ $? -ne 0 ] && { echo "$ip"; exit 1; }
    [ "$1" == "off" ] && ssh -i /home/admin/iot-testbed/ssh/rpbi_testbed testbed@${ip} touch ina260-zmq-publisher/publisher_${ina260}_break
    [ "$1" == "on" ]  && ssh -i /home/admin/iot-testbed/ssh/rpbi_testbed testbed@${ip} rm -f ina260-zmq-publisher/publisher_${ina260}_break
done