#!/bin/sh

AMBARI_AGENT_INI="/etc/ambari-agent/conf/ambari-agent.ini"
FORCE_HTTPS_CONF="force_https_protocol=PROTOCOL_TLSv1_2"

if [ $test_only -eq 0 ]; then
    if grep -q '\[security\]' ${AMBARI_AGENT_INI}; then
        if ! grep -q "${FORCE_HTTPS_CONF}" ${AMBARI_AGENT_INI}; then
            sed -i '/^\[security\]/a\'${FORCE_HTTPS_CONF} ${AMBARI_AGENT_INI}
        fi
    else
        printf "[security]\n${FORCE_HTTPS_CONF}\n" >>${AMBARI_AGENT_INI}
    fi
else
    grep -q "${FORCE_HTTPS_CONF}" ${AMBARI_AGENT_INI}
    exit $?
fi
