-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompleteInstall.ps1
More file actions
222 lines (182 loc) · 7.66 KB
/
CompleteInstall.ps1
File metadata and controls
222 lines (182 loc) · 7.66 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
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Combined installation script for Godspeed CLI, daemon, and required dependencies.
#>
Write-Host "Starting Godspeed Full Installation..." -ForegroundColor Cyan
#region Admin Check
$currentPrincipal = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
if (-not $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "This script must be run as Administrator. Please right-click and 'Run as Administrator'." -ForegroundColor Red
exit
}
#endregion
#region Node.js and NVM Setup
Write-Host "`nChecking Node.js installation..." -ForegroundColor Cyan
# Improved NVM detection
$nvmInstalled = $false
try {
$nvmVersion = cmd /c nvm version 2>&1
if (-not ($nvmVersion -match "not recognized")) {
$nvmInstalled = $true
$nvmPath = (Get-ItemProperty "HKCU:\Environment").NVM_HOME
}
} catch { }
# Check existing Node installation
$nodeInstalled = Get-Command node -ErrorAction SilentlyContinue
if ($nodeInstalled) {
Write-Host "Node.js detected. Checking installation source..."
if (-not $nvmInstalled) {
Write-Host "NVM not detected. Checking for winget installation..."
$wingetNode = winget list --id OpenJS.NodeJS | Select-String -Pattern 'OpenJS.NodeJS'
if ($wingetNode) {
Write-Host "Removing winget-installed Node.js..."
winget uninstall -e --id OpenJS.NodeJS
}
else {
Write-Host "Non-NVM Node.js installation detected. Please remove manually and restart the script." -ForegroundColor Red
exit
}
}
}
# Install/Update NVM
if (-not $nvmInstalled) {
Write-Host "Installing NVM for Windows..." -ForegroundColor Cyan
winget install -e --id CoreyButler.NVMforWindows
# Force refresh environment variables
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# Set NVM_HOME if not present
$nvmHome = [Environment]::GetEnvironmentVariable("NVM_HOME", "User")
if (-not $nvmHome) {
$nvmDir = "${env:ProgramFiles}\NVM for Windows"
[Environment]::SetEnvironmentVariable("NVM_HOME", $nvmDir, "User")
$env:NVM_HOME = $nvmDir
}
# Wait for environment to update
Write-Host "Waiting for environment to update..." -ForegroundColor Yellow
Start-Sleep -Seconds 10
# Verify NVM is now available
try {
$nvmCheck = cmd /c nvm version 2>&1
if ($nvmCheck -match "not recognized") {
throw "NVM still not recognized"
}
$nvmInstalled = $true
} catch {
Write-Host "NVM installation verification failed. Please restart your shell and run the script again." -ForegroundColor Red
exit
}
}
# Install Node.js via NVM
Write-Host "Installing Node.js LTS via NVM..." -ForegroundColor Cyan
cmd /c "nvm install lts"
cmd /c "nvm use lts"
# Force refresh PATH after NVM changes
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# Verify Node and npm are available
try {
$nodeVersion = node -v
$npmVersion = npm -v
Write-Host "Node.js version: $nodeVersion"
Write-Host "npm version: $npmVersion"
} catch {
Write-Host "Node/npm commands not available. Trying to refresh environment..." -ForegroundColor Yellow
# Additional environment refresh attempts
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
$env:Path += ";$env:NVM_HOME"
# Final verification
if (-not (Get-Command node -ErrorAction SilentlyContinue)) {
Write-Host "Node/npm still not available. Please restart your shell and run the script again." -ForegroundColor Red
exit
}
}
# Enable Corepack and pnpm
Write-Host "Configuring package managers..." -ForegroundColor Cyan
try {
corepack enable
corepack prepare pnpm@latest --activate
} catch {
Write-Host "Corepack commands failed. Trying alternative approach..." -ForegroundColor Yellow
# Add Node.js global binaries to PATH if not already there
$nodePath = cmd /c "nvm which current" | Select-Object -First 1
$nodeDir = [System.IO.Path]::GetDirectoryName($nodePath)
if (-not $env:Path.Contains($nodeDir)) {
$env:Path += ";$nodeDir"
}
# Retry corepack
corepack enable
corepack prepare pnpm@latest --activate
}
#endregion
#region Git Installation
Write-Host "`nInstalling Git..." -ForegroundColor Cyan
winget install -e --id Git.Git
# Refresh environment variables after Git installation
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
# Verify Git installation
try {
# Get Git installation path from registry
$gitInstallPath = (Get-ItemProperty "HKLM:\SOFTWARE\GitForWindows").InstallPath
if ($gitInstallPath -and (-not $env:Path.Contains($gitInstallPath))) {
$env:Path += ";$gitInstallPath\bin"
[Environment]::SetEnvironmentVariable("Path", "$($env:Path);$gitInstallPath\bin", "User")
}
# Check if git command is now available
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
throw "Git command still not available"
}
Write-Host "Git version: $(git --version)"
} catch {
Write-Host "Git installation verification failed. Please restart your shell to access Git commands." -ForegroundColor Yellow
}
#endregion
#region CLI Installation
Write-Host "`nInstalling Godspeed CLI..." -ForegroundColor Cyan
npm install -g @godspeedsystems/godspeed
#endregion
# #region Daemon Installation
# Write-Host "`nStarting Daemon Installation..." -ForegroundColor Cyan
# $daemonUrl = "https://github.com/zero8dotdev/install-godspeed-daemon/releases/download/v1.1.2/godspeed-daemon-win.exe"
# $targetDir = "$env:USERPROFILE\AppData\Local\Programs\godspeed"
# $destinationPath = "$targetDir\godspeed-daemon.exe"
# # Create installation directory
# if (-not (Test-Path $targetDir)) {
# New-Item -Path $targetDir -ItemType Directory -Force | Out-Null
# }
# # Download daemon
# try {
# Write-Host "Downloading godspeed-daemon..."
# Invoke-WebRequest -Uri $daemonUrl -OutFile $destinationPath -ErrorAction Stop
# }
# catch {
# Write-Host "Download failed: $_" -ForegroundColor Red
# exit
# }
# # Add to PATH
# $persistentPath = [Environment]::GetEnvironmentVariable('Path', 'User')
# if (-not $persistentPath.Contains($targetDir)) {
# [Environment]::SetEnvironmentVariable('Path', "$persistentPath;$targetDir", 'User')
# $env:Path += ";$targetDir"
# }
# # Verify installation
# if (-not (Test-Path $destinationPath)) {
# Write-Host "Daemon installation failed!" -ForegroundColor Red
# exit
# }
# # Configuration setup
# $godspeedDir = Join-Path $env:USERPROFILE ".godspeed"
# $servicesJson = Join-Path $godspeedDir "services.json"
# if (-not (Test-Path $godspeedDir)) {
# New-Item -Path $godspeedDir -ItemType Directory | Out-Null
# }
# if (-not (Test-Path $servicesJson)) {
# [System.IO.File]::WriteAllText($servicesJson, '{ "services": [] }', [System.Text.UTF8Encoding]::new($false))
# }
# Write-Host "Daemon installation completed successfully!" -ForegroundColor Green
# #endregion
# Final checks
Write-Host "`nVerifying installations..." -ForegroundColor Cyan
Write-Host "Node.js version: $(node -v)"
Write-Host "npm version: $(npm -v)"
Write-Host "Git version: $(git --version)"
Write-Host "`nInstallation complete! Please restart your terminal for all changes to take effect." -ForegroundColor Green