-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
335 lines (287 loc) · 8.47 KB
/
install.ps1
File metadata and controls
335 lines (287 loc) · 8.47 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#
# Heidi CLI One-Click Installer for Windows
#
# This script will:
# 1. Clone the latest Heidi CLI from main branch
# 2. Build and install it
# 3. Verify installation
# 4. Clean up temporary files
#
# Usage: .\install.ps1
#
#Requires -RunAsAdministrator
param(
[string]$InstallPath = "$env:USERPROFILE\heidi-cli",
[switch]$Force
)
# Colors for output
$Colors = @{
Red = "Red"
Green = "Green"
Yellow = "Yellow"
Blue = "Blue"
Cyan = "Cyan"
Magenta = "Magenta"
}
# Print functions
function Write-Header {
Write-Host "================================" -ForegroundColor $Colors.Magenta
Write-Host "🚀 Heidi CLI One-Click Installer" -ForegroundColor $Colors.Magenta
Write-Host "================================" -ForegroundColor $Colors.Magenta
Write-Host ""
}
function Write-Success {
param([string]$Message)
Write-Host "✅ $Message" -ForegroundColor $Colors.Green
}
function Write-Info {
param([string]$Message)
Write-Host "ℹ️ $Message" -ForegroundColor $Colors.Blue
}
function Write-Warning {
param([string]$Message)
Write-Host "⚠️ $Message" -ForegroundColor $Colors.Yellow
}
function Write-Error {
param([string]$Message)
Write-Host "❌ $Message" -ForegroundColor $Colors.Red
}
function Write-Step {
param([string]$Message)
Write-Host "🔄 $Message" -ForegroundColor $Colors.Cyan
}
# Check if running as Administrator
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# Check system requirements
function Test-Requirements {
Write-Step "Checking system requirements..."
# Check Python
try {
$python = Get-Command python -ErrorAction Stop
$pythonVersion = & python --version 2>&1
Write-Success "Python found: $pythonVersion"
}
catch {
Write-Error "Python is required but not installed"
Write-Info "Please install Python 3.10 or higher from https://python.org"
exit 1
}
# Check pip
try {
$pip = Get-Command pip -ErrorAction Stop
Write-Success "pip found"
}
catch {
Write-Error "pip is required but not installed"
Write-Info "Please install pip"
exit 1
}
# Check git
try {
$git = Get-Command git -ErrorAction Stop
Write-Success "git found"
}
catch {
Write-Error "git is required but not installed"
Write-Info "Please install git from https://git-scm.com"
exit 1
}
Write-Success "All requirements satisfied"
}
# Create temporary directory
function New-TempDirectory {
$tempDir = Join-Path $env:TEMP "heidi-cli-install-$(Get-Random)"
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
Write-Info "Created temporary directory: $tempDir"
return $tempDir
}
# Clone Heidi CLI
function Invoke-CloneHeidi {
param([string]$TempDir)
Write-Step "Cloning Heidi CLI from main branch..."
$repoUrl = "https://github.com/heidi-dang/heidi-cli.git"
$cloneDir = Join-Path $tempDir "heidi-cli"
try {
& git clone $repoUrl $cloneDir
Set-Location $cloneDir
Write-Success "Heidi CLI cloned successfully"
# Show current commit info
$commitHash = & git rev-parse HEAD
$commitDate = & git log -1 --format="%cd" --date=short
Write-Info "Installing commit: $commitHash ($commitDate)"
}
catch {
Write-Error "Failed to clone Heidi CLI repository"
exit 1
}
}
# Setup virtual environment
function New-VirtualEnvironment {
Write-Step "Setting up virtual environment..."
try {
& python -m venv venv
& venv\Scripts\Activate.ps1
Write-Success "Virtual environment created and activated"
# Upgrade pip
& python -m pip install --upgrade pip
Write-Success "pip upgraded"
}
catch {
Write-Error "Failed to create virtual environment"
exit 1
}
}
# Install dependencies
function Install-Dependencies {
Write-Step "Installing dependencies..."
try {
& pip install -e .
Write-Success "Dependencies installed"
}
catch {
Write-Error "Failed to install Heidi CLI dependencies"
exit 1
}
}
# Build Heidi CLI
function Build-Heidi {
Write-Step "Building Heidi CLI..."
try {
# Check if build tools are available
if (Get-Command "python -m build" -ErrorAction SilentlyContinue) {
& python -m build
Write-Success "Heidi CLI built with modern build system"
} else {
# Fallback to setup.py
& python setup.py build
Write-Success "Heidi CLI built with setup.py"
}
}
catch {
Write-Error "Failed to build Heidi CLI"
exit 1
}
}
# Install Heidi CLI
function Install-Heidi {
Write-Step "Installing Heidi CLI..."
try {
& pip install -e . --user
Write-Success "Heidi CLI installed successfully"
}
catch {
Write-Error "Failed to install Heidi CLI"
exit 1
}
}
# Verify installation
function Test-Installation {
Write-Step "Verifying installation..."
# Check if heidi command is available
try {
$heidi = Get-Command heidi -ErrorAction Stop
Write-Success "heidi command is available"
# Show version
try {
$version = & heidi --version 2>$null
Write-Success "Heidi CLI version: $version"
}
catch {
Write-Warning "Could not get version - this is normal for first run"
}
# Test basic functionality
try {
& heidi --help >$null 2>&1
Write-Success "Heidi CLI help command works"
}
catch {
Write-Warning "Heidi CLI help command failed - installation may have issues"
}
}
catch {
Write-Error "heidi command not found after installation"
Write-Info "You may need to restart your terminal or add Python Scripts to PATH"
exit 1
}
}
# Run post-install setup
function Invoke-PostInstallSetup {
Write-Step "Running post-install setup..."
# Initialize Heidi CLI
try {
& heidi doctor >$null 2>&1
Write-Success "Heidi CLI initialization successful"
}
catch {
Write-Warning "Heidi CLI initialization had issues - this is normal for first run"
}
# Show next steps
Write-Host ""
Write-Info "🎉 Installation completed successfully!"
Write-Host ""
Write-Info "Next steps:"
Write-Host " 1. Run: heidi setup"
Write-Host " 2. Generate API key: heidi api generate -name 'My Key'"
Write-Host " 3. Start model server: heidi model serve"
Write-Host " 4. View help: heidi --help"
Write-Host ""
Write-Info "Documentation: https://github.com/heidi-dang/heidi-cli/blob/main/docs/how-to-use.md"
}
# Cleanup temporary files
function Remove-TempFiles {
param([string]$TempDir)
Write-Step "Cleaning up temporary files..."
try {
Set-Location $env:USERPROFILE
Remove-Item -Path $TempDir -Recurse -Force
Write-Success "Temporary files cleaned up"
}
catch {
Write-Warning "Failed to clean up temporary files: $TempDir"
}
}
# Error handling
function Handle-Error {
Write-Error "Installation failed!"
Write-Info "Check the error messages above for details"
Write-Info "You can try running the installer again"
if ($TempDir) {
Remove-TempFiles -TempDir $TempDir
}
exit 1
}
# Main installation function
function Main {
Write-Header
# Set up error handling
trap { Handle-Error } ERR
# Check if running as Administrator
if (-not (Test-Administrator)) {
Write-Warning "Not running as Administrator - installing for current user only"
}
# Run installation steps
Test-Requirements
$tempDir = New-TempDirectory
Invoke-CloneHeidi -TempDir $tempDir
New-VirtualEnvironment
Install-Dependencies
Build-Heidi
Install-Heidi
Test-Installation
Invoke-PostInstallSetup
# Cleanup
Remove-TempFiles -TempDir $tempDir
Write-Success "🎉 Heidi CLI installation completed successfully!"
Write-Info "You can now use: heidi --version"
}
# Run main function
try {
Main
}
catch {
Handle-Error
}