#!/bin/sh
set -eu

CONFIG_DIR="${CONFIG_DIR:-/mosquitto/config}"
RUNTIME_CONF="${RUNTIME_CONF:-/tmp/mosquitto.conf}"
MQTT_TLS_ENABLED="${MQTT_TLS_ENABLED:-true}"

case "$MQTT_TLS_ENABLED" in
    true|1|yes|on)
        cp "$CONFIG_DIR/mosquitto-tls.conf" "$RUNTIME_CONF"
        ;;
    *)
        cp "$CONFIG_DIR/mosquitto-plain.conf" "$RUNTIME_CONF"
        ;;
esac

exec mosquitto -c "$RUNTIME_CONF"