#!/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

# load configuration
cat "${ZOOKEEPER_CONFIG_DIR}/myid" > "${ZOOKEEPER_DATA_DIR}/myid"
cat "${ZOOKEEPER_CONFIG_DIR}"/zookeeper.properties > "${CP_COMPONENT_SCRIPT_DIR}/${CP_COMPONENT_NAME}.properties"
cat "${ZOOKEEPER_CONFIG_DIR}"/shared/zookeeper.properties >> "${CP_COMPONENT_SCRIPT_DIR}/${CP_COMPONENT_NAME}.properties"
cat "${ZOOKEEPER_CONFIG_DIR}"/log4j.properties > "${CP_COMPONENT_SCRIPT_DIR}/log4j.properties"
cat "${ZOOKEEPER_CONFIG_DIR}"/shared/log4j.properties >> "${CP_COMPONENT_SCRIPT_DIR}/log4j.properties"
cat "${ZOOKEEPER_CONFIG_DIR}"/shared/disk-usage-agent.properties >  "${CP_COMPONENT_SCRIPT_DIR}/disk-usage-agent.properties"
cat "${ZOOKEEPER_CONFIG_DIR}"/jvm.config > "${CP_COMPONENT_SCRIPT_DIR}/jvm.config"
cat "${ZOOKEEPER_CONFIG_DIR}"/shared/jvm.config >> "${CP_COMPONENT_SCRIPT_DIR}/jvm.config"
if [ -e "${ZOOKEEPER_CONFIG_DIR}/shared/jolokia.config" ]; then
  cat "${ZOOKEEPER_CONFIG_DIR}"/shared/jolokia.config > "${CP_COMPONENT_SCRIPT_DIR}/jolokia.config"
fi
