#!/bin/bash

export KAFKA_BROKER_ID=${KAFKA_BROKER_ID:-0}
export KAFKA_HOST_NAME=${KAFKA_HOST_NAME:-localhost}
export KAFKA_LISTENERS=${KAFKA_LISTENERS:-PLAINTEXT://0.0.0.0:9092}
export KAFKA_ADVERTISED_LISTENERS=${KAFKA_ADVERTISED_LISTENERS:-${KAFKA_LISTENERS}}
export KAFKA_ZOOKEEPER_CONNECT=${KAFKA_ZOOKEEPER_CONNECT:-zookeeper:2181}
export LOG_DIR=${LOG_DIR:-/data/kafka-logs}
mkdir -p $LOG_DIR
envsubst < /kafka/config/server.properties_sample >/kafka/config/server.properties

export OS_HOSTNAME=${OS_HOSTNAME:-kafka}
sed "/`hostname`/ s/$/ ${OS_HOSTNAME}/" /etc/hosts > /tmp/tmphost.txt
cat /tmp/tmphost.txt >/etc/hosts
