#!/usr/bin/env bash
# Instala módulo FOSSBilling ↔ OpenPanel dentro do container
set -euo pipefail
cd "$(dirname "$0")"
COMPOSE="docker compose --env-file .env -f docker-compose.yml"

$COMPOSE up -d fossbilling foss-mariadb
sleep 5

$COMPOSE exec fossbilling bash -c '
  curl -fsSL -o /var/www/html/library/Server/Manager/OpenPanel.php \
    https://raw.githubusercontent.com/stefanpejcic/FOSSBilling-OpenPanel/main/OpenPanel.php
  cp /var/www/html/library/Server/Manager/OpenPanel.php /var/www/html/library/Server/Manager/Openpanel.php
  chown www-data:www-data /var/www/html/library/Server/Manager/OpenPanel.php /var/www/html/library/Server/Manager/Openpanel.php
  echo "Módulo OpenPanel instalado (Openpanel.php para autoload FOSS)."
'

echo "FOSSBilling: System → Hosting Plans and Servers → New Server"
echo "  Manager: openpanel | Port: 2087 | Hostname: 10.10.10.123"
echo "Ou: bash setup-foss-openpanel-server.sh"
