-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall-red-engine.ps1
More file actions
113 lines (94 loc) · 4.04 KB
/
Copy pathinstall-red-engine.ps1
File metadata and controls
113 lines (94 loc) · 4.04 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "🚀 Installing RED Engine (Production Mode)..." -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
if (-Not (Test-Path "docker-compose.yml")) {
Write-Host "[*] Repository not detected in current directory."
if (-Not (Get-Command "git" -ErrorAction SilentlyContinue)) {
Write-Host "❌ Error: 'git' is not installed. Please install Git for Windows to continue." -ForegroundColor Red
Exit
}
Write-Host "[*] Cloning RED Engine repository..."
git clone https://github.com/RED-Collective/red-engine.git
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Error: Failed to clone repository." -ForegroundColor Red
Exit
}
Write-Host "[*] Navigating into red-engine directory..."
Set-Location "red-engine"
} else {
Write-Host "[*] Running from inside existing repository."
}
if (-Not (Test-Path ".\data")) {
Write-Host "[*] Creating .\data directory..."
New-Item -ItemType Directory -Path ".\data" | Out-Null
} else {
Write-Host "[*] .\data directory already exists."
}
if (-Not (Test-Path "config.json")) {
Write-Host "[*] Generating default config.json..."
$Bytes = New-Object Byte[] 16
[System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($Bytes)
$NewToken = [BitConverter]::ToString($Bytes) -replace '-'
$DefaultConfig = @{
addr = ":8080"
siteName = "RED Engine"
dataDir = "/app/data"
adminToken = $NewToken
startupSync = @()
}
$DefaultConfig | ConvertTo-Json -Depth 10 | Set-Content "config.json"
Write-Host "[*] Generated secure Admin Token: $NewToken" -ForegroundColor Green
Write-Host "⚠️ PLEASE SAVE THIS TOKEN! You will need it to log in to the admin panel." -ForegroundColor Yellow
} else {
Write-Host "[*] config.json already exists. Skipping default generation."
}
if (-Not (Test-Path "contributors.json")) {
Write-Host "[*] Generating default contributors.json..."
"[]" | Set-Content "contributors.json"
} else {
Write-Host "[*] contributors.json already exists."
}
$ComposeCmd = ""
$ComposeArgs = @("up", "--build", "-d")
if (Get-Command "podman-compose" -ErrorAction SilentlyContinue) {
$ComposeCmd = "podman-compose"
} elseif (Get-Command "docker-compose" -ErrorAction SilentlyContinue) {
$ComposeCmd = "docker-compose"
} elseif (Get-Command "docker" -ErrorAction SilentlyContinue) {
try {
$null = Invoke-Expression "docker compose version 2>&1"
if ($LASTEXITCODE -eq 0) {
$ComposeCmd = "docker"
$ComposeArgs = @("compose", "up", "--build", "-d")
}
} catch {}
}
if ($ComposeCmd -eq "") {
Write-Host "❌ Error: Neither podman-compose nor docker compose found on this system." -ForegroundColor Red
Write-Host "Please install Podman or Docker Desktop to continue." -ForegroundColor Red
Exit
}
Write-Host "[*] Starting RED Engine using container engine..." -ForegroundColor Green
& $ComposeCmd $ComposeArgs
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Error: Failed to start containers." -ForegroundColor Red
Exit
}
$ConfigPort = "8080"
if (Test-Path "config.json") {
$ConfigRaw = Get-Content "config.json" -Raw | ConvertFrom-Json -ErrorAction SilentlyContinue
if ($ConfigRaw -and $ConfigRaw.addr -match ':(\d+)') {
$ConfigPort = $Matches[1]
}
}
$HostIP = "localhost"
$IPAddresses = [System.Net.Dns]::GetHostAddresses((System.Net.Dns]::GetHostName())) |
Where-Object { $_.AddressFamily -eq 'InterNetwork' -and $_.IPAddressToString -notlike '127.*' }
if ($IPAddresses) {
$HostIP = $IPAddresses[0].IPAddressToString
}
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "✅ Installation Complete!" -ForegroundColor Green
Write-Host "🌐 Your node is running at: http://${HostIP}:${ConfigPort}"
Write-Host "⚙️ Admin Panel: http://${HostIP}:${ConfigPort}/-/admin"
Write-Host "========================================" -ForegroundColor Cyan