-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathinstall.ps1
More file actions
173 lines (147 loc) · 6.52 KB
/
Copy pathinstall.ps1
File metadata and controls
173 lines (147 loc) · 6.52 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
# opengate Windows Installer
# Run: powershell -ExecutionPolicy Bypass -c "curl.exe -sSL https://raw.githubusercontent.com/youssefvdel/opengate/main/install.ps1 | iex"
$ErrorActionPreference = "Stop"
$Repo = "https://github.com/youssefvdel/opengate.git"
$Dir = "$PWD\opengate"
$DefaultPort = 26405
# ── Helpers ──────────────────────────────────────────────────────────
function Info { Write-Host " -> " -ForegroundColor Cyan -NoNewline; Write-Host $args }
function Ok { Write-Host " OK " -ForegroundColor Green -NoNewline; Write-Host $args }
function Warn { Write-Host " !! " -ForegroundColor Yellow -NoNewline; Write-Host $args }
function Fail { Write-Host " ERROR " -ForegroundColor Red -NoNewline; Write-Host $args; exit 1 }
function Test-Command {
param([string]$Name)
$null -ne (Get-Command $Name -ErrorAction SilentlyContinue)
}
# ── Banner ───────────────────────────────────────────────────────────
Write-Host ""
Write-Host " ========================================" -ForegroundColor Cyan
Write-Host " opengate Windows Installer" -ForegroundColor Cyan
Write-Host " ========================================" -ForegroundColor Cyan
Write-Host ""
# ── 1. Git (required) ───────────────────────────────────────────────
Info "Checking for git..."
if (-not (Test-Command "git")) {
Fail "git is required but not found. Install from https://git-scm.com"
}
Ok "git $(git --version)"
# ── 2. Bun (preferred) / Node.js (fallback) ────────────────────────
$UseBun = $false
$UseNode = $false
Info "Checking for Bun..."
if (Test-Command "bun") {
$UseBun = $true
Ok "bun v$(bun --version)"
} else {
Warn "Bun not found — attempting install..."
try {
irm bun.sh/install.ps1 | iex
if (Test-Command "bun") {
$UseBun = $true
Ok "Bun installed (v$(bun --version))"
}
} catch {
Warn "Auto-install failed. Trying npm -g bun..."
try {
npm install -g bun 2>$null
if (Test-Command "bun") {
$UseBun = $true
Ok "Bun installed via npm (v$(bun --version))"
}
} catch { }
}
if (-not $UseBun) {
Warn "Bun not available — falling back to Node.js"
if (-not (Test-Command "node")) {
Fail "Neither Bun nor Node.js found. Install Bun: https://bun.sh"
}
if (-not (Test-Command "npm")) {
Fail "Node.js found but npm is missing. Reinstall Node.js from https://nodejs.org"
}
$NodeVer = (node -v) -replace 'v', '' -split '\.' | Select-Object -First 1
if ([int]$NodeVer -lt 18) {
Fail "Node.js >= 18 required (found v$(node -v))"
}
Ok "node v$(node -v), npm v$(npm -v) (fallback)"
$UseNode = $true
}
}
# ── 3. Clone or update ──────────────────────────────────────────────
if (Test-Path "$Dir") {
Info "Existing installation found — updating..."
git -C "$Dir" pull --ff-only 2>$null
if ($LASTEXITCODE -ne 0) {
Warn "git pull failed — using existing code"
} else {
Ok "Repository updated"
}
} else {
Info "Cloning $Repo..."
git clone "$Repo" "$Dir" 2>$null
if ($LASTEXITCODE -ne 0) {
Fail "git clone failed — check your internet connection"
}
Ok "Repository cloned"
}
# ── 4. Install dependencies ─────────────────────────────────────────
Info "Installing dependencies..."
Set-Location "$Dir"
if ($UseBun) {
bun install --frozen-lockfile 2>$null
if ($LASTEXITCODE -ne 0) { bun install }
if ($LASTEXITCODE -ne 0) { Fail "bun install failed" }
Ok "Dependencies installed via bun"
} else {
npm install 2>$null
if ($LASTEXITCODE -ne 0) { Fail "npm install failed" }
Ok "Dependencies installed via npm"
}
# ── 4b. Install Playwright browsers ────────────────────────────────
Info "Installing Playwright browsers..."
try {
npx playwright install 2>$null
if ($LASTEXITCODE -ne 0) {
Warn "Playwright browser install returned non-zero exit code — continuing anyway"
} else {
Ok "Playwright browsers installed"
}
} catch {
Warn "Playwright browser install failed — continuing anyway ($_ )"
}
# ── 5. Configuration ────────────────────────────────────────────────
if (-not (Test-Path "$Dir\config.json")) {
Info "config.json will be auto-generated on first start"
} else {
Ok "config.json already exists (skipped)"
}
# ── 6. Add bin/ to user PATH ────────────────────────────────────────
$BinDir = "$Dir\bin"
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($UserPath -notlike "*$BinDir*") {
[Environment]::SetEnvironmentVariable("Path", "$UserPath;$BinDir", "User")
$env:Path = "$env:Path;$BinDir"
Ok "Added $BinDir to user PATH"
} else {
Ok "bin/ already in PATH"
}
# ── 7. Success banner ───────────────────────────────────────────────
Write-Host ""
Write-Host " ========================================" -ForegroundColor Green
Write-Host " opengate installed successfully!" -ForegroundColor Green
Write-Host " ========================================" -ForegroundColor Green
Write-Host ""
Write-Host " Runtime: $(if ($UseBun) { 'Bun' } else { 'Node.js' })" -ForegroundColor White
Write-Host " Directory: $Dir" -ForegroundColor White
Write-Host " Port: $DefaultPort" -ForegroundColor White
Write-Host ""
Write-Host " Commands:" -ForegroundColor Yellow
Write-Host " opengate Start the server"
Write-Host " opengate update Update to latest"
Write-Host " opengate restart Restart server"
Write-Host " opengate status Check if running"
Write-Host ""
Write-Host " Dashboard: http://localhost:$DefaultPort/dashboard" -ForegroundColor Cyan
Write-Host " API: http://localhost:$DefaultPort/v1" -ForegroundColor Cyan
Write-Host ""
Write-Host " Restart your terminal, then run 'opengate' to start." -ForegroundColor Gray
Write-Host ""