-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.ps1
More file actions
263 lines (221 loc) Β· 11.3 KB
/
install.ps1
File metadata and controls
263 lines (221 loc) Β· 11.3 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<#
.SYNOPSIS
OpenWhale Windows Installer
.DESCRIPTION
Automated setup script for OpenWhale on Windows.
Clones the repository, checks/installs prerequisites, installs dependencies, and starts the server.
.NOTES
Run this script in PowerShell as Administrator for best results.
Usage: Right-click > Run with PowerShell, or: powershell -ExecutionPolicy Bypass -File install.ps1
#>
param(
[string]$InstallDir = "$env:USERPROFILE\openwhale",
[switch]$SkipStart
)
$ErrorActionPreference = "Stop"
# ββ Colors & Helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
function Write-Banner {
Write-Host ""
Write-Host " ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Cyan
Write-Host " β β" -ForegroundColor Cyan
Write-Host " β π OpenWhale Windows Installer π β" -ForegroundColor Cyan
Write-Host " β β" -ForegroundColor Cyan
Write-Host " ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Cyan
Write-Host ""
}
function Write-Step {
param([string]$Message)
Write-Host ""
Write-Host " βΆ $Message" -ForegroundColor Yellow
Write-Host " $('β' * 56)" -ForegroundColor DarkGray
}
function Write-Success {
param([string]$Message)
Write-Host " β
$Message" -ForegroundColor Green
}
function Write-Info {
param([string]$Message)
Write-Host " βΉοΈ $Message" -ForegroundColor DarkCyan
}
function Write-Warn {
param([string]$Message)
Write-Host " β οΈ $Message" -ForegroundColor DarkYellow
}
function Write-Fail {
param([string]$Message)
Write-Host " β $Message" -ForegroundColor Red
}
function Test-CommandExists {
param([string]$Command)
$null -ne (Get-Command $Command -ErrorAction SilentlyContinue)
}
# ββ Main ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Write-Banner
$resolvedDir = [System.IO.Path]::GetFullPath($InstallDir)
Write-Host " π Install location: " -NoNewline -ForegroundColor White
Write-Host "$resolvedDir" -ForegroundColor Cyan
Write-Host ""
# ββ Step 1: Check Git βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Write-Step "Checking Git..."
if (Test-CommandExists "git") {
$gitVersion = (git --version) -replace "git version ", ""
Write-Success "Git found: v$gitVersion"
} else {
Write-Warn "Git not found. Attempting install via winget..."
if (Test-CommandExists "winget") {
winget install --id Git.Git -e --source winget --accept-package-agreements --accept-source-agreements
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
if (Test-CommandExists "git") {
Write-Success "Git installed successfully!"
} else {
Write-Fail "Git installation failed. Please install manually from https://git-scm.com/download/win"
Write-Host " Then re-run this script." -ForegroundColor Gray
exit 1
}
} else {
Write-Fail "Git is not installed and winget is not available."
Write-Host " Please install Git from: https://git-scm.com/download/win" -ForegroundColor Gray
exit 1
}
}
# ββ Step 2: Check Node.js βββββββββββββββββββββββββββββββββββββββββββββββββββββ
Write-Step "Checking Node.js..."
if (Test-CommandExists "node") {
$nodeVersion = (node -v).TrimStart("v")
$nodeMajor = [int]($nodeVersion.Split(".")[0])
if ($nodeMajor -ge 22) {
Write-Success "Node.js found: v$nodeVersion"
} else {
Write-Warn "Node.js v$nodeVersion found, but v22+ is required."
Write-Info "Attempting upgrade via winget..."
if (Test-CommandExists "winget") {
winget install --id OpenJS.NodeJS.LTS -e --source winget --accept-package-agreements --accept-source-agreements
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
} else {
Write-Fail "Please upgrade Node.js manually from https://nodejs.org/"
exit 1
}
}
} else {
Write-Warn "Node.js not found. Attempting install via winget..."
if (Test-CommandExists "winget") {
winget install --id OpenJS.NodeJS.LTS -e --source winget --accept-package-agreements --accept-source-agreements
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
if (Test-CommandExists "node") {
Write-Success "Node.js installed successfully!"
} else {
Write-Fail "Node.js installation failed. Please install manually from https://nodejs.org/"
exit 1
}
} else {
Write-Fail "Node.js is not installed and winget is not available."
Write-Host " Please install Node.js 22+ from: https://nodejs.org/" -ForegroundColor Gray
exit 1
}
}
# ββ Step 3: Check/Install pnpm ββββββββββββββββββββββββββββββββββββββββββββββββ
Write-Step "Checking pnpm..."
if (Test-CommandExists "pnpm") {
$pnpmVersion = (pnpm -v)
Write-Success "pnpm found: v$pnpmVersion"
} else {
Write-Info "Installing pnpm..."
# Try corepack first (built into Node 22+, avoids execution policy issues)
try {
corepack enable 2>$null
corepack prepare pnpm@latest --activate 2>$null
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
} catch {}
if (-not (Test-CommandExists "pnpm")) {
Write-Info "Corepack method unavailable, trying npm install..."
# Temporarily bypass execution policy for this process
try { Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force } catch {}
npm install -g pnpm
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
}
if (Test-CommandExists "pnpm") {
Write-Success "pnpm installed successfully!"
} else {
Write-Fail "pnpm installation failed."
Write-Host " Fix: Run this command first, then re-run the installer:" -ForegroundColor Gray
Write-Host " Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser" -ForegroundColor White
exit 1
}
}
# ββ Step 4: Clone Repository ββββββββββββββββββββββββββββββββββββββββββββββββββ
Write-Step "Cloning OpenWhale repository..."
if (Test-Path "$resolvedDir\.git") {
Write-Info "Repository already exists at $resolvedDir"
Write-Info "Pulling latest changes..."
Push-Location $resolvedDir
git pull origin main
Pop-Location
Write-Success "Repository updated!"
} else {
Write-Info "Cloning to: $resolvedDir"
git clone https://github.com/viralcode/openwhale.git "$resolvedDir"
if ($LASTEXITCODE -ne 0) {
Write-Fail "Failed to clone repository. Check your internet connection."
exit 1
}
Write-Success "Repository cloned successfully!"
}
# ββ Step 5: Install Dependencies ββββββββββββββββββββββββββββββββββββββββββββββ
Write-Step "Installing dependencies..."
Push-Location $resolvedDir
Write-Info "Running pnpm install (this may take a few minutes)..."
pnpm install
if ($LASTEXITCODE -ne 0) {
Write-Warn "pnpm install had issues. Trying with npm fallback..."
npm install
}
# ββ Step 6: Approve Native Module Builds ββββββββββββββββββββββββββββββββββββββ
Write-Step "Building native modules..."
Write-Info "Running pnpm approve-builds (select all when prompted)..."
pnpm approve-builds
Write-Success "Native modules built!"
# ββ Step 7: Setup Environment βββββββββββββββββββββββββββββββββββββββββββββββββ
Write-Step "Setting up environment..."
if (-not (Test-Path ".env")) {
if (Test-Path ".env.example") {
Copy-Item ".env.example" ".env"
Write-Success "Created .env from .env.example"
Write-Info "Edit .env to add your AI provider API keys."
} else {
Write-Warn "No .env.example found β you may need to create .env manually."
}
} else {
Write-Success ".env already exists β skipping."
}
Pop-Location
# ββ Done ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Write-Host ""
Write-Host " ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Green
Write-Host " β β" -ForegroundColor Green
Write-Host " β β
OpenWhale installed successfully! β
β" -ForegroundColor Green
Write-Host " β β" -ForegroundColor Green
Write-Host " ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ" -ForegroundColor Green
Write-Host ""
Write-Host " π Location: $resolvedDir" -ForegroundColor White
Write-Host " π Dashboard: http://localhost:7777/dashboard" -ForegroundColor White
Write-Host ""
Write-Host " Next steps:" -ForegroundColor Yellow
Write-Host " 1. cd $resolvedDir" -ForegroundColor Gray
Write-Host " 2. Edit .env and add your AI API keys" -ForegroundColor Gray
Write-Host " 3. pnpm run dev" -ForegroundColor Gray
Write-Host " 4. Open http://localhost:7777/dashboard" -ForegroundColor Gray
Write-Host " 5. Login with admin / admin" -ForegroundColor Gray
Write-Host ""
if (-not $SkipStart) {
$startNow = Read-Host " π Start OpenWhale now? (Y/n)"
if ($startNow -ne "n" -and $startNow -ne "N") {
Write-Host ""
Write-Info "Starting OpenWhale..."
Write-Info "Press Ctrl+C to stop the server."
Write-Host ""
Push-Location $resolvedDir
pnpm run dev
Pop-Location
}
}