#!/bin/bash

# Script to create secret file from template
# Usage: ./create-secret-file-from-template.sh /path/to/template /path/to/output

TEMPLATE_FILE="${1:-honey-config.properties.template}"
OUTPUT_FILE="${2:-/run/secrets/honey-config.properties}"
OUTPUT_DIR=$(dirname "$OUTPUT_FILE")

# Check if template exists
if [ ! -f "$TEMPLATE_FILE" ]; then
    echo "❌ Template file not found: $TEMPLATE_FILE"
    exit 1
fi

# Create output directory if it doesn't exist
mkdir -p "$OUTPUT_DIR"

# Copy template to output
cp "$TEMPLATE_FILE" "$OUTPUT_FILE"

# Set secure permissions (read-only for owner, no access for others)
chmod 600 "$OUTPUT_FILE"

echo "✅ Secret file created at $OUTPUT_FILE"
echo "⚠️  IMPORTANT: Edit this file and replace all placeholder values with your actual configuration!"
echo "⚠️  After editing, ensure permissions are secure: chmod 600 $OUTPUT_FILE"



