#!/bin/bash
set -e

CONFIG_DIR="/etc/samba/configs.d"
INCLUDE_FILE="/etc/samba/includes.conf"

echo "# Generated by orion-update-smb-includes" > "$INCLUDE_FILE"
echo "# Do not edit this file manually. Use $CONFIG_DIR/*.conf files instead." >> "$INCLUDE_FILE"

# Scan all .conf files and generate include lines
if [ -d "$CONFIG_DIR" ]; then
    for f in "$CONFIG_DIR"/*.conf; do
        if [ -f "$f" ]; then
            echo "   include = $f" >> "$INCLUDE_FILE"
        fi
    done
fi

# Reload Samba if it's running
if systemctl is-active --quiet smbd; then
    systemctl reload smbd || true
fi

exit 0
