Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
222 lines (199 loc) · 8.19 KB
/
Copy pathinstall.ps1
File metadata and controls
222 lines (199 loc) · 8.19 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#requires -Version 5.1
# ═══════════════════════════════════════════════════════════════════════════════
# MAGNATRIX-OS Installer — Windows PowerShell
# ═══════════════════════════════════════════════════════════════════════════════
# Usage:
# iwr -useb https://raw.githubusercontent.com/Magnatrix-Lab/MAGNATRIX-OS/main/install.ps1 | iex
# # Or locally:
# .\install.ps1
# ═══════════════════════════════════════════════════════════════════════════════
param(
[string]$InstallDir = "$env:USERPROFILE\MAGNATRIX-OS",
[string]$DataDir = "$env:USERPROFILE\.magnatrix"
)
$ErrorActionPreference = "Stop"
function Write-Info { param($m) Write-Host "[INFO] $m" -ForegroundColor Cyan }
function Write-Ok { param($m) Write-Host "[OK] $m" -ForegroundColor Green }
function Write-Warn { param($m) Write-Host "[WARN] $m" -ForegroundColor Yellow }
function Write-Err { param($m) Write-Host "[ERR] $m" -ForegroundColor Red }
function Check-Deps {
Write-Info "Checking dependencies..."
$missing = @()
# Python
$py = Get-Command python -ErrorAction SilentlyContinue
if (-not $py) {
$py = Get-Command python3 -ErrorAction SilentlyContinue
}
if (-not $py) {
$missing += "python3"
} else {
$ver = & $py.Source -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')"
if ([version]$ver -lt [version]"3.10") {
Write-Err "Python $ver found, but >= 3.10 required"
$missing += "python3 (>= 3.10)"
}
}
# Git
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
$missing += "git"
}
# Docker (optional)
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
Write-Warn "Docker not found. Docker mode unavailable."
}
if ($missing.Count -gt 0) {
Write-Err "Missing dependencies: $($missing -join ', ')"
Write-Info "Install with winget:"
Write-Info " winget install Python.Python.3.12 Git.Git Docker.DockerDesktop"
exit 1
}
Write-Ok "All required dependencies present"
}
function Clone-Repo {
if (Test-Path "$InstallDir\.git") {
Write-Info "Existing installation found — updating..."
Set-Location $InstallDir
git fetch origin
git reset --hard origin/main
} else {
Write-Info "Cloning MAGNATRIX-OS..."
if (Test-Path $InstallDir) { Remove-Item -Recurse -Force $InstallDir }
git clone --depth 1 "https://github.com/Magnatrix-Lab/MAGNATRIX-OS.git" $InstallDir
}
Write-Ok "Repository ready"
}
function Setup-DataDir {
Write-Info "Setting up data directory: $DataDir"
$dirs = @("models","knowledge","logs","config","repos","vault")
foreach ($d in $dirs) {
New-Item -ItemType Directory -Force -Path "$DataDir\$d" | Out-Null
}
Write-Ok "Data directory ready"
}
function Setup-Python {
Write-Info "Setting up Python environment..."
Set-Location $InstallDir
if (-not (Test-Path ".venv")) {
& (Get-Command python).Source -m venv .venv
}
.\.venv\Scripts\Activate.ps1
python -m pip install --no-cache-dir --upgrade pip setuptools wheel
python -m pip install --no-cache-dir -e ".[all]"
Write-Ok "Python environment ready"
}
function Build-Engines {
# C++ (requires Visual Studio or MinGW)
Write-Info "Checking C++ build tools..."
if (Get-Command cmake -ErrorAction SilentlyContinue) {
Set-Location "$InstallDir\trading\cpp_hft_engine"
New-Item -ItemType Directory -Force -Path "build" | Out-Null
Set-Location build
cmake .. -DCMAKE_BUILD_TYPE=Release 2>$null
if ($LASTEXITCODE -eq 0) {
cmake --build . --config Release 2>$null
if ($LASTEXITCODE -eq 0) { Write-Ok "C++ engine built" }
else { Write-Warn "C++ build failed — Python fallback active" }
} else {
Write-Warn "CMake failed — C++ Python fallback active"
}
} else {
Write-Warn "CMake not found — C++ Python fallback active"
}
# Rust
Write-Info "Checking Rust..."
if (Get-Command cargo -ErrorAction SilentlyContinue) {
Set-Location "$InstallDir\security\rust_crypto_engine"
cargo build --release 2>$null
if ($LASTEXITCODE -eq 0) { Write-Ok "Rust engine built" }
else { Write-Warn "Rust build failed — Python fallback active" }
} else {
Write-Warn "Cargo not found — Rust Python fallback active"
}
}
function Run-Tests {
Write-Info "Running tests..."
Set-Location $InstallDir
.\.venv\Scripts\Activate.ps1
python tests\run_all_tests.py 2>$null
if ($LASTEXITCODE -eq 0) { Write-Ok "All tests passed" }
else { Write-Warn "Some tests failed (non-blocking)" }
}
function Create-Launcher {
Write-Info "Creating launcher..."
$binDir = "$env:USERPROFILE\.local\bin"
New-Item -ItemType Directory -Force -Path $binDir | Out-Null
$launcher = @'
@echo off
set INSTALL_DIR=%MAGNATRIX_INSTALL_DIR%
if "%INSTALL_DIR%"=="" set INSTALL_DIR=%USERPROFILE%\MAGNATRIX-OS
set DATA_DIR=%MAGNATRIX_DATA_DIR%
if "%DATA_DIR%"=="" set DATA_DIR=%USERPROFILE%\.magnatrix
cd /d "%INSTALL_DIR%"
if "%~1"=="boot" (
call .venv\Scripts\activate.bat
python magnatrix.py boot %*
) else if "%~1"=="docker" (
docker compose up -d
) else if "%~1"=="test" (
call .venv\Scripts\activate.bat
python tests\run_all_tests.py
) else if "%~1"=="stop" (
docker compose down 2>nul
taskkill /F /IM "python.exe" 2>nul
) else if "%~1"=="status" (
call .venv\Scripts\activate.bat
python magnatrix.py status
) else if "%~1"=="update" (
cd /d "%INSTALL_DIR%"
git fetch origin && git reset --hard origin/main
call .venv\Scripts\activate.bat
pip install --no-cache-dir -e ".[all]"
echo MAGNATRIX-OS updated.
) else (
echo MAGNATRIX-OS — Super AI Control Interface
echo Usage: magnatrix ^<command^>
echo boot Start MAGNATRIX-OS
echo docker Start with Docker Compose
echo test Run all tests
echo stop Stop MAGNATRIX-OS
echo status Show layer status
echo update Update to latest
)
'@
Set-Content -Path "$binDir\magnatrix.bat" -Value $launcher
Write-Ok "Launcher installed: $binDir\magnatrix.bat"
Write-Info "Add to PATH: [Environment]::SetEnvironmentVariable('Path', "$binDir;" + \$env:Path, 'User')"
}
function Main {
Write-Host ""
Write-Host " __ __ _ ____ _____ ____" -ForegroundColor Cyan
Write-Host " | \/ | __ _ _ __ ___ _ _ _ __ __ _| |_ ___/ ___| |_ _/ ___|" -ForegroundColor Cyan
Write-Host " | |\/| |/ _' | '_ \` _ \| | | | '_ \ / _' | __/ _ \___ \ | | \___ \ " -ForegroundColor Cyan
Write-Host " | | | | (_| | | | | | | |_| | | | | (_| | || __/___) | | | ___) |" -ForegroundColor Cyan
Write-Host " |_| |_|\__,_|_| |_| |_|\__,_|_| |_|\__, |\__\___|____/ |_| |____/" -ForegroundColor Cyan
Write-Host " |___/" -ForegroundColor Cyan
Write-Host ""
Write-Host "MAGNATRIX-OS Installer — Windows" -ForegroundColor Cyan
Write-Host "=================================" -ForegroundColor Cyan
Write-Host ""
Check-Deps
Clone-Repo
Setup-DataDir
Setup-Python
Build-Engines
Run-Tests
Create-Launcher
Write-Host ""
Write-Host "MAGNATRIX-OS installed successfully!" -ForegroundColor Green
Write-Host ""
Write-Info "Installation: $InstallDir"
Write-Info "Data: $DataDir"
Write-Info "Launcher: $env:USERPROFILE\.local\bin\magnatrix.bat"
Write-Host ""
Write-Info "Quick start:"
Write-Info " magnatrix boot Start MAGNATRIX-OS"
Write-Info " magnatrix docker Start with Docker"
Write-Info " magnatrix test Run tests"
Write-Host ""
}
Main