#!/bin/bash

ENV_FILE=".env"
TEMPLATE_FILE=".env.example"

# Генерация пароля
generate_password() {
  openssl rand -base64 18
}

# Создание .env на основе шаблона
if [ -f "$ENV_FILE" ]; then
  echo "[INFO] $ENV_FILE already exists. Skipping creation."
else
  echo "[INFO] Creating $ENV_FILE from $TEMPLATE_FILE..."

  # Копируем шаблон
  cp "$TEMPLATE_FILE" "$ENV_FILE"

  # Генерируем и подставляем RCON пароль
  RCON_PASSWORD=$(generate_password)
  echo "RCON_PASSWORD=$RCON_PASSWORD" >> "$ENV_FILE"

  echo "[OK] .env created with generated RCON_PASSWORD:"
  echo "$RCON_PASSWORD"
fi