#!/usr/bin/env bash
set -euo pipefail

CMK_INSTANCE=$(omd sites -b)
for i in $CMK_INSTANCE; do
    sudo -u $i -i bash -c "cmk-site-bootstrap"
    usermod -aG cmkpush $i
    omd stop $i
    omd start $i
    echo "Your checkmk site $i is now configured for the bashclub push agent."
    echo "To register a new agent, please use the following data:"
    echo "CMKSERVER=$(hostname -f)"
    cat /omd/sites/$i/.credentials
done
