#!/usr/bin/env bash
#
# Copyright 2020 Confluent Inc.
#
set -o nounset
set -o errexit

if [ ! -d "${CP_COMPONENT_SCRIPT_DIR}" ]; then
 mkdir -p "${CP_COMPONENT_SCRIPT_DIR}"
fi

cat "${CONNECT_CONFIG_DIR}/${CP_COMPONENT_NAME}.properties" > "${CP_COMPONENT_SCRIPT_DIR}/${CP_COMPONENT_NAME}.properties"
cat "${CONNECT_CONFIG_DIR}/shared/${CP_COMPONENT_NAME}.properties" >> "${CP_COMPONENT_SCRIPT_DIR}/${CP_COMPONENT_NAME}.properties"
cat "${CONNECT_CONFIG_DIR}/log4j.properties" > "${CP_COMPONENT_SCRIPT_DIR}/log4j.properties"
cat "${CONNECT_CONFIG_DIR}/shared/log4j.properties" >>  "${CP_COMPONENT_SCRIPT_DIR}/log4j.properties"
if [ -e "${CONNECT_CONFIG_DIR}/shared/disk-usage-agent.properties" ]; then
  cat "${CONNECT_CONFIG_DIR}/shared/disk-usage-agent.properties" >  "${CP_COMPONENT_SCRIPT_DIR}/disk-usage-agent.properties"
fi
cat "${CONNECT_CONFIG_DIR}/jvm.config" > "${CP_COMPONENT_SCRIPT_DIR}/jvm.config"
cat "${CONNECT_CONFIG_DIR}/shared/jvm.config" >> "${CP_COMPONENT_SCRIPT_DIR}/jvm.config"
if [ -e "${CONNECT_CONFIG_DIR}/shared/jolokia.config" ]; then
  cat "${CONNECT_CONFIG_DIR}/shared/jolokia.config" > "${CP_COMPONENT_SCRIPT_DIR}/jolokia.config"
fi
if [ -e "${CONNECT_CONFIG_DIR}/log4j2/log4j2.yaml" ]; then
  cat "${CONNECT_CONFIG_DIR}/log4j2/log4j2.yaml" > "${CP_COMPONENT_SCRIPT_DIR}/log4j2.yaml"
fi
