#!/usr/bin/env bash

# do jinja things
printf '%s\n' "Rendering config files"
if [ "${DEBUG_MODE}" = 'true' ]; then
  printf '%s\n' 'Running in verbose mode'
  python3 "${MAXWELL_ROOT_DIR}/config.py" --verbose \
    --config-template "${MAXWELL_ROOT_DIR}/config.properties.jinja2" \
    --config-file "${MAXWELL_ROOT_DIR}/config.properties" || exit 1
  python3 "${MAXWELL_ROOT_DIR}/config.py" --verbose \
    --config-template "${MAXWELL_ROOT_DIR}/kinesis-producer-library.properties.jinja2" \
    --config-file "${MAXWELL_ROOT_DIR}/kinesis-producer-library.properties" || exit 1
else
  python3 "${MAXWELL_ROOT_DIR}/config.py" \
    --config-template "${MAXWELL_ROOT_DIR}/config.properties.jinja2" \
    --config-file "${MAXWELL_ROOT_DIR}/config.properties" || exit 1
  python3 "${MAXWELL_ROOT_DIR}/config.py" \
    --config-template "${MAXWELL_ROOT_DIR}/kinesis-producer-library.properties.jinja2" \
    --config-file "${MAXWELL_ROOT_DIR}/kinesis-producer-library.properties" || exit 1
fi

# do something else important
exec "${MAXWELL_ROOT_DIR}/bin/maxwell"
