diff --git a/mqtt/unsec/docker-compose-auto.yml b/mqtt/unsec/docker-compose-auto.yml new file mode 100644 index 0000000..2215a82 --- /dev/null +++ b/mqtt/unsec/docker-compose-auto.yml @@ -0,0 +1,54 @@ +services: + mosquitto: + image: eclipse-mosquitto:2 + container_name: ${CONTAINER_NAME:-mosquitto} + restart: unless-stopped + + environment: + TZ: ${TZ:-Europe/Berlin} + MQTT_USER: ${MQTT_USER:-mqttuser} + MQTT_PORT: ${MQTT_PORT:-1883} + + volumes: + - ${CONFIG_PATH:-./config}:/mosquitto/config + - ${DATA_PATH:-./data}:/mosquitto/data + - ${LOG_PATH:-./log}:/mosquitto/log + + ports: + - "${MQTT_PORT:-1883}:1883" + + dns: + - ${DNS_SERVER} + + command: + - sh + - -c + - | + CONF=/mosquitto/config/mosquitto.conf + PASSWD=/mosquitto/config/passwd + + echo "=== Checking mosquitto.conf ===" + if [ ! -f "$CONF" ]; then + echo "Generating mosquitto.conf..." + printf '%s\n' \ + "listener ${MQTT_PORT:-1883}" \ + "allow_anonymous false" \ + "password_file /mosquitto/config/passwd" \ + > "$CONF" + else + echo "Existing mosquitto.conf found." + fi + + echo "=== Checking user ===" + if [ ! -f "$PASSWD" ]; then + echo "Generating random password for user: $MQTT_USER" + RANDOM_PASS=$(tr -dc A-Za-z0-9