#!/bin/bash

set -xe

conf='/opt/rh/ruby193/root/etc/mcollective/client.cfg'
command cp -f "$conf"{,.ugsave.`date +%Y-%m-%d-%H:%M:%S`}

# Remove the old settings in case they were there
sed -i '/logger_type/d' $conf
sed -i '/loglevel/d' $conf

cat <<EOF >> "$conf"

plugin.activemq.heartbeat_interval = 30
plugin.activemq.max_hbread_fails = 2
plugin.activemq.max_hbrlck_fails = 2

# logger_type = file cannot be set for OpenShift Enterprise
# https://bugzilla.redhat.com/show_bug.cgi?id=963332
logger_type = console
loglevel = warn
EOF

# Comment out the logfile so people don't get confused. It's actually only used
# if logger_type = file.
sed -i 's|^logfile\(.*\)$|#logfile\1|' $conf

# 2.4 upgrade
sed -i '/topicprefix/d' $conf
sed -i 's|^direct_addressing.*$|direct_addressing = 0|' $conf
