-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathinstall.ps1
More file actions
185 lines (167 loc) · 5.96 KB
/
install.ps1
File metadata and controls
185 lines (167 loc) · 5.96 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
# OpenBrowser Installer for Windows (PowerShell)
# Usage: irm https://raw.githubusercontent.com/billy-enrizky/openbrowser-ai/main/install.ps1 | iex
# Or: .\install.ps1 [-NoBrowser]
$ErrorActionPreference = 'Stop'
$PACKAGE = "openbrowser-ai"
$MIN_PYTHON_MAJOR = 3
$MIN_PYTHON_MINOR = 12
# --- Colors ---
function Write-Info { param([string]$Msg) Write-Host $Msg -ForegroundColor Green }
function Write-Warn { param([string]$Msg) Write-Host $Msg -ForegroundColor Yellow }
function Write-Err { param([string]$Msg) Write-Host $Msg -ForegroundColor Red }
function Write-Bold { param([string]$Msg) Write-Host $Msg -ForegroundColor White -BackgroundColor DarkGray }
# --- Parse args ---
$SkipBrowser = $false
foreach ($a in $args) {
switch ($a) {
'--no-browser' { $SkipBrowser = $true }
'-NoBrowser' { $SkipBrowser = $true }
{ $_ -in '--help', '-h' } {
Write-Host "Usage: install.ps1 [OPTIONS]"
Write-Host ""
Write-Host "Options:"
Write-Host " --no-browser Skip Chromium installation"
Write-Host " -h, --help Show this help message"
exit 0
}
}
}
# --- Find Python 3.12+ ---
$Python = $null
function Find-Python {
# Try py launcher with specific versions first, then generic commands
$candidates = @(
@{ Cmd = 'py'; Args = @('-3', '--version') ; Run = 'py'; RunArgs = @('-3') },
@{ Cmd = 'py'; Args = @('-3.13', '--version') ; Run = 'py'; RunArgs = @('-3.13') },
@{ Cmd = 'py'; Args = @('-3.12', '--version') ; Run = 'py'; RunArgs = @('-3.12') },
@{ Cmd = 'python3'; Args = @('--version') ; Run = 'python3'; RunArgs = @() },
@{ Cmd = 'python'; Args = @('--version') ; Run = 'python'; RunArgs = @() }
)
foreach ($c in $candidates) {
try {
$null = Get-Command $c.Cmd -ErrorAction Stop
$versionOutput = & $c.Cmd @($c.Args) 2>&1 | Out-String
if ($versionOutput -match '(\d+)\.(\d+)\.(\d+)') {
$major = [int]$Matches[1]
$minor = [int]$Matches[2]
if ($major -gt $MIN_PYTHON_MAJOR -or ($major -eq $MIN_PYTHON_MAJOR -and $minor -ge $MIN_PYTHON_MINOR)) {
$script:Python = @{ Cmd = $c.Run; RunArgs = $c.RunArgs; Version = "$major.$minor.$($Matches[3])" }
return $true
}
}
}
catch {
continue
}
}
return $false
}
function Invoke-Python {
param([string[]]$Arguments)
$p = $script:Python
$allArgs = $p.RunArgs + $Arguments
& $p.Cmd @allArgs
}
function Get-PythonDisplay {
$p = $script:Python
if ($p.RunArgs.Count -gt 0) {
return "$($p.Cmd) $($p.RunArgs -join ' ')"
}
return $p.Cmd
}
# --- Install methods (in preference order) ---
function Install-WithUv {
try { $null = Get-Command 'uv' -ErrorAction Stop } catch { return $false }
Write-Info "Installing with uv..."
& uv tool install $PACKAGE
if ($LASTEXITCODE -ne 0) { return $false }
return $true
}
function Install-WithPipx {
try { $null = Get-Command 'pipx' -ErrorAction Stop } catch { return $false }
Write-Info "Installing with pipx..."
$pythonExe = (Invoke-Python -Arguments @('-c', 'import sys; print(sys.executable)')).Trim()
& pipx install --python $pythonExe $PACKAGE
if ($LASTEXITCODE -ne 0) { return $false }
return $true
}
function Install-WithPip {
if (-not $script:Python) { return $false }
$display = Get-PythonDisplay
Write-Info "Installing with $display -m pip..."
Invoke-Python -Arguments @('-m', 'pip', 'install', $PACKAGE)
if ($LASTEXITCODE -ne 0) { return $false }
return $true
}
# --- Main ---
Write-Bold "OpenBrowser Installer"
Write-Host "====================="
Write-Host ""
# OS info
$arch = if ([Environment]::Is64BitOperatingSystem) { "x86_64" } else { "x86" }
$osVersion = [System.Environment]::OSVersion.VersionString
Write-Host " OS: Windows ($arch) - $osVersion"
if (-not (Find-Python)) {
Write-Err "Python ${MIN_PYTHON_MAJOR}.${MIN_PYTHON_MINOR}+ is required but not found."
Write-Host ""
Write-Host "Install Python:"
Write-Host " winget install Python.Python.3.12"
Write-Host " https://www.python.org/downloads/"
exit 1
}
$pyDisplay = Get-PythonDisplay
Write-Host " Python: $pyDisplay (Python $($script:Python.Version))"
Write-Host ""
$Installer = $null
if (Install-WithUv) {
$Installer = "uv"
}
elseif (Install-WithPipx) {
$Installer = "pipx"
}
elseif (Install-WithPip) {
$Installer = "pip"
}
else {
Write-Err "No Python package manager found."
Write-Host ""
Write-Host "Install one of: uv, pipx, or pip"
Write-Host " powershell -ExecutionPolicy ByPass -c `"irm https://astral.sh/uv/install.ps1 | iex`""
Write-Host " pip install pipx"
Write-Host " pipx ensurepath"
exit 1
}
# --- Install Chromium ---
if (-not $SkipBrowser) {
Write-Host ""
Write-Info "Installing Chromium browser..."
try {
$null = Get-Command 'openbrowser-ai' -ErrorAction Stop
& openbrowser-ai install 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Warn "Chromium install failed (run 'openbrowser-ai install' manually)"
}
}
catch {
try {
$null = Get-Command 'uvx' -ErrorAction Stop
& uvx playwright install chromium 2>$null
if ($LASTEXITCODE -ne 0) {
Write-Warn "Chromium install failed (run 'openbrowser-ai install' manually)"
}
}
catch {
Write-Warn "Chromium install skipped. Please run 'openbrowser-ai install' manually after installation completes."
}
}
}
# --- Done ---
Write-Host ""
Write-Info "OpenBrowser installed successfully! (via $Installer)"
Write-Host ""
Write-Host " Get started:"
Write-Host " openbrowser-ai --help"
Write-Host " openbrowser-ai -c `"await navigate('https://example.com')`""
Write-Host ""
Write-Host " Docs: https://docs.openbrowser.me"
Write-Host ""