File size: 3,130 Bytes
5a81b95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# WidgeTDC Windows Deployment Script
# Kører på din host maskine for at omgå container-begrænsninger
# Usage: .\scripts\deploy_windows.ps1

Write-Host "Starting WidgeTDC Deployment Protocol (Windows Mode)..." -ForegroundColor Cyan

# 1. Setup Directories
$DataDir = ".\data"
$CivicSchemaDir = "$DataDir\civic_schema"
$ThreatFeedDir = "$DataDir\threat_feeds"
$SourceIntelDir = ".\source_intel"

if (-not (Test-Path $CivicSchemaDir)) { New-Item -ItemType Directory -Force -Path $CivicSchemaDir | Out-Null }
if (-not (Test-Path $ThreatFeedDir)) { New-Item -ItemType Directory -Force -Path $ThreatFeedDir | Out-Null }

# 2. Data Sanitization (The Scrubber)
$SourceSql = "$DataDir\full_schema.sql"
$TargetSql = "$CivicSchemaDir\init.sql"

if (Test-Path $SourceSql) {
    Write-Host "Scrubbing 'full_schema.sql'..." -ForegroundColor Yellow
    $content = Get-Content $SourceSql -Raw
    $content = $content -replace 'cia_user', 'civic_reader'
    $content = $content -replace 'cia', 'civic_vault'
    $content = $content -replace 'Citizen Intelligence Agency', 'Civic Insight Node'
    Set-Content -Path $TargetSql -Value $content
    Write-Host "Civic Vault Sanitized." -ForegroundColor Green
} else {
    Write-Host "'full_schema.sql' not found in $DataDir. Civic Node will start empty." -ForegroundColor Red
    # Create dummy init to prevent crash
    "CREATE TABLE IF NOT EXISTS system_status (status VARCHAR(50)); INSERT INTO system_status VALUES ('WAITING_FOR_DATA');" | Set-Content $TargetSql
}

# 3. Threat Feed Staging
if (Test-Path $SourceIntelDir) {
    $feeds = Get-ChildItem "$SourceIntelDir\*.md"
    if ($feeds) {
        Write-Host "Staging Threat Intelligence..." -ForegroundColor Yellow
        Copy-Item "$SourceIntelDir\*.md" -Destination $ThreatFeedDir -Force
        Write-Host "Intel Feeds staged." -ForegroundColor Green
    } else {
        Write-Host "No .md files found in $SourceIntelDir." -ForegroundColor Gray
    }
}

# 3.5 Ensure Dockerfiles Exist (Fix for Sync Issues)
$FrontendDockerfile = "apps\matrix-frontend\Dockerfile"
if (-not (Test-Path $FrontendDockerfile)) {
    Write-Host "Repairing missing Frontend Dockerfile..." -ForegroundColor Yellow
    $dockerContent = @"
FROM node:20-alpine AS builder
WORKDIR /app
COPY package.json package-lock.json ./
COPY apps/matrix-frontend/package.json ./apps/matrix-frontend/
COPY apps/backend/package.json ./apps/backend/
COPY packages/mcp-types/package.json ./packages/mcp-types/
COPY packages/domain-types/package.json ./packages/domain-types/
RUN npm ci --legacy-peer-deps
COPY . .
WORKDIR /app/apps/matrix-frontend
RUN npm run build
FROM nginx:alpine
COPY --from=builder /app/apps/matrix-frontend/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
"@
    Set-Content -Path $FrontendDockerfile -Value $dockerContent
    Write-Host "Frontend Dockerfile restored." -ForegroundColor Green
}

# 4. Launch Docker
Write-Host "Launching Containers..." -ForegroundColor Cyan
docker-compose up -d --build

Write-Host "SYSTEM ONLINE." -ForegroundColor Green
Write-Host "   - Civic Node: Port 5433"
Write-Host "   - Backend:    Port 3001"