# ============================================================================= # Aegis Initialization Script (PowerShell) # ============================================================================= # This script initializes the Aegis platform after starting Docker containers. # # Usage: # .\scripts\init.ps1 # ============================================================================= $ErrorActionPreference = "Stop" Write-Host "╔═══════════════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan Write-Host "║ Aegis - Platform Initialization ║" -ForegroundColor Cyan Write-Host "╚═══════════════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan Write-Host "" function Write-Status { param([string]$Message) Write-Host "[✓] $Message" -ForegroundColor Green } function Write-Warning { param([string]$Message) Write-Host "[!] $Message" -ForegroundColor Yellow } function Write-Error { param([string]$Message) Write-Host "[✗] $Message" -ForegroundColor Red } # Check if Docker is running try { docker info | Out-Null } catch { Write-Error "Docker is not running. Please start Docker first." exit 1 } # Check if containers are running $backendRunning = docker-compose ps | Select-String "aegis-backend" if (-not $backendRunning) { Write-Warning "Containers not running. Starting them now..." docker-compose up -d Write-Host "" Write-Host "Waiting for services to be healthy..." Start-Sleep -Seconds 10 } # Wait for backend to be ready Write-Host "Waiting for backend to be ready..." $maxRetries = 30 $retryCount = 0 $ready = $false while (-not $ready -and $retryCount -lt $maxRetries) { try { $response = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing -TimeoutSec 2 if ($response.StatusCode -eq 200) { $ready = $true } } catch { $retryCount++ Write-Host " Waiting... ($retryCount/$maxRetries)" Start-Sleep -Seconds 2 } } if (-not $ready) { Write-Error "Backend failed to start after $maxRetries attempts" exit 1 } Write-Status "Backend is healthy" # Run database migrations Write-Host "" Write-Host "Running database migrations..." docker-compose exec -T backend alembic upgrade head Write-Status "Migrations completed" # Seed admin user Write-Host "" Write-Host "Seeding admin user..." try { docker-compose exec -T backend python -m app.seed 2>$null Write-Status "Admin user ready" } catch { Write-Warning "Admin user may already exist" } # Ask about MITRE sync Write-Host "" $runSync = Read-Host "Do you want to run initial MITRE ATT&CK sync? (y/N)" if ($runSync -eq "y" -or $runSync -eq "Y") { Write-Host "Triggering MITRE sync (this may take a minute)..." try { # Get admin token $loginBody = "username=admin&password=admin123" $loginResponse = Invoke-RestMethod -Uri "http://localhost:8000/api/v1/auth/login" ` -Method Post -Body $loginBody -ContentType "application/x-www-form-urlencoded" $token = $loginResponse.access_token if ($token) { $headers = @{ "Authorization" = "Bearer $token" } Invoke-RestMethod -Uri "http://localhost:8000/api/v1/system/sync-mitre" ` -Method Post -Headers $headers | Out-Null Write-Status "MITRE sync triggered" } } catch { Write-Warning "Could not authenticate. Run sync manually from the System page." } } # Print summary Write-Host "" Write-Host "╔═══════════════════════════════════════════════════════════════════════╗" -ForegroundColor Cyan Write-Host "║ Aegis is ready! ║" -ForegroundColor Cyan Write-Host "╠═══════════════════════════════════════════════════════════════════════╣" -ForegroundColor Cyan Write-Host "║ ║" -ForegroundColor Cyan Write-Host "║ Frontend: http://localhost:5173 ║" -ForegroundColor White Write-Host "║ Backend API: http://localhost:8000 ║" -ForegroundColor White Write-Host "║ Swagger UI: http://localhost:8000/docs ║" -ForegroundColor White Write-Host "║ MinIO Console: http://localhost:9001 ║" -ForegroundColor White Write-Host "║ ║" -ForegroundColor Cyan Write-Host "║ Default login: admin / admin123 ║" -ForegroundColor Yellow Write-Host "║ ║" -ForegroundColor Cyan Write-Host "║ ⚠️ Change the default password in production! ║" -ForegroundColor Yellow Write-Host "║ ║" -ForegroundColor Cyan Write-Host "╚═══════════════════════════════════════════════════════════════════════╝" -ForegroundColor Cyan Write-Host ""