-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathinstall.ps1
More file actions
241 lines (207 loc) · 7.27 KB
/
Copy pathinstall.ps1
File metadata and controls
241 lines (207 loc) · 7.27 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
# OpenCompany Installer for Windows
# Usage: iwr -useb https://raw.githubusercontent.com/zeenie-ai/OpenCompany/main/install.ps1 | iex
#
# This script installs OpenCompany and its dependencies:
# - Node.js 22+ (via winget/choco)
# - Python 3.12+ (via winget/choco)
# - uv (Python package manager)
$ErrorActionPreference = "Stop"
$MIN_NODE_VERSION = 22
$MIN_PYTHON_VERSION = "3.12"
# Colors
function Write-Color {
param([string]$Text, [string]$Color = "White")
Write-Host $Text -ForegroundColor $Color
}
function Info { Write-Color "[INFO] $args" "Cyan" }
function Success { Write-Color "[OK] $args" "Green" }
function Warn { Write-Color "[WARN] $args" "Yellow" }
function Error-Exit { Write-Color "[ERROR] $args" "Red"; exit 1 }
# Banner
Write-Host ""
Write-Color " OpenCompany" "Cyan"
Write-Host ""
Write-Host "Open-source workflow automation with AI agents"
Write-Host ""
# Check if command exists
function Has-Command {
param([string]$Command)
$null -ne (Get-Command $Command -ErrorAction SilentlyContinue)
}
# Get package manager
function Get-PackageManager {
if (Has-Command "winget") { return "winget" }
if (Has-Command "choco") { return "choco" }
return $null
}
# Refresh PATH from registry
function Refresh-Path {
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
}
# =============================================================================
# Dependency Checks and Installation
# =============================================================================
function Check-Node {
if (Has-Command "node") {
$version = (node --version) -replace "v", ""
$major = [int]($version.Split(".")[0])
if ($major -ge $MIN_NODE_VERSION) {
Success "Node.js v$version"
return $true
}
Warn "Node.js v$version is too old (need v$MIN_NODE_VERSION+)"
}
return $false
}
function Install-Node {
Info "Installing Node.js $MIN_NODE_VERSION..."
$pm = Get-PackageManager
switch ($pm) {
"winget" {
winget install OpenJS.NodeJS.LTS --accept-package-agreements --accept-source-agreements
}
"choco" {
choco install nodejs-lts -y
}
default {
Error-Exit "Please install winget or chocolatey, or install Node.js manually from https://nodejs.org/"
}
}
Refresh-Path
if (-not (Check-Node)) {
Error-Exit "Failed to install Node.js. Please install manually and restart PowerShell."
}
}
function Check-Python {
foreach ($cmd in @("python", "python3")) {
if (Has-Command $cmd) {
$versionOutput = & $cmd --version 2>&1
if ($versionOutput -match "Python (\d+)\.(\d+)") {
$major = [int]$Matches[1]
$minor = [int]$Matches[2]
if ($major -ge 3 -and $minor -ge 12) {
Success "Python $major.$minor ($cmd)"
$script:PYTHON_CMD = $cmd
return $true
}
}
}
}
Warn "Python $MIN_PYTHON_VERSION+ not found"
return $false
}
function Install-Python {
Info "Installing Python $MIN_PYTHON_VERSION..."
$pm = Get-PackageManager
switch ($pm) {
"winget" {
winget install Python.Python.3.12 --accept-package-agreements --accept-source-agreements
}
"choco" {
choco install python312 -y
}
default {
Error-Exit "Please install winget or chocolatey, or install Python manually from https://python.org/"
}
}
Refresh-Path
if (-not (Check-Python)) {
Error-Exit "Failed to install Python. Please install manually and restart PowerShell."
}
}
function Check-Uv {
if (Has-Command "uv") {
$version = (uv --version) -replace "uv ", ""
Success "uv $version"
return $true
}
return $false
}
function Install-Uv {
Info "Installing uv (Python package manager)..."
# Try pip first
if ($script:PYTHON_CMD) {
try {
& $script:PYTHON_CMD -m pip install uv 2>&1 | Out-Null
Refresh-Path
if (Check-Uv) { return }
} catch {}
}
# Fallback to official installer
Invoke-RestMethod https://astral.sh/uv/install.ps1 | Invoke-Expression
$env:Path = "$env:USERPROFILE\.local\bin;$env:Path"
if (-not (Check-Uv)) {
Error-Exit "Failed to install uv"
}
}
# The pre-rebrand package owns the deprecated `machina` command too. Remove it
# before installing OpenCompany so npm does not fail with an existing shim.
function Remove-LegacyMachinaOs {
npm list -g --depth=0 machinaos *> $null
if ($LASTEXITCODE -ne 0) { return }
Info "Removing legacy machinaos package..."
npm uninstall -g machinaos
if ($LASTEXITCODE -ne 0) {
Error-Exit "Unable to remove legacy machinaos. Run PowerShell as Administrator and retry."
}
Success "Legacy machinaos package removed"
}
# =============================================================================
# Main Installation Flow
# =============================================================================
function Main {
Write-Host ""
Info "Checking dependencies..."
Write-Host ""
# Check and install dependencies
if (-not (Check-Node)) { Install-Node }
if (-not (Check-Python)) { Install-Python }
if (-not (Check-Uv)) { Install-Uv }
# Avoid a collision with the deprecated `machina` compatibility shim.
Remove-LegacyMachinaOs
Write-Host ""
Info "Installing OpenCompany..."
Write-Host ""
# Install OpenCompany from npm
npm install -g "@zeenie-ai/opencompany"
if ($LASTEXITCODE -ne 0) {
Error-Exit "npm install -g failed. Run PowerShell as Administrator and retry."
}
Write-Host ""
Write-Color "============================================" "Green"
Write-Color " OpenCompany installed successfully!" "Green"
Write-Color "============================================" "Green"
Write-Host ""
Write-Host " Start OpenCompany:"
Write-Host " company start"
Write-Host ""
Write-Host " Open in browser:"
# .env.template ships inside the installed package. This used to read it
# from the working directory, which is wherever the user ran the script --
# so it printed a bare "http://localhost:", and dereferencing .Matches on
# the null result could fault outright. Resolve through npm's global root.
$appPort = $null
$npmRoot = (npm root -g 2>$null | Select-Object -First 1)
if ($npmRoot) {
$templatePath = Join-Path $npmRoot "@zeenie-ai/opencompany/.env.template"
if (Test-Path $templatePath) {
$match = Select-String -Path $templatePath -Pattern "^PYTHON_BACKEND_PORT=(\d+)" |
Select-Object -First 1
if ($match) { $appPort = $match.Matches.Groups[1].Value }
}
}
if ($appPort) {
Write-Host " http://localhost:$appPort"
} else {
Write-Host " the URL printed by 'company start'"
}
Write-Host ""
Write-Host " For development from source, install pnpm:"
Write-Host " npm install -g pnpm"
Write-Host ""
Write-Host " Run diagnostics:"
Write-Host " company doctor"
Write-Host ""
}
# Run main
Main