#!/bin/bash
# BunkerM init script - create MQTT user and start services
set -e

# Create MQTT user if password file is empty or doesn't exist
if [ ! -s /etc/mosquitto/mosquitto_passwd ]; then
    echo "Creating bunker MQTT user..."
    mosquitto_passwd -b /etc/mosquitto/mosquitto_passwd bunker bunker 2>/dev/null || true
    chown root:root /etc/mosquitto/mosquitto_passwd 2>/dev/null || true
    chmod 0700 /etc/mosquitto/mosquitto_passwd 2>/dev/null || true
fi

# Execute the original entrypoint
exec /bin/sh -c '/docker-entrypoint.sh'
