-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.ps1
More file actions
284 lines (247 loc) · 12.2 KB
/
Copy pathinstall.ps1
File metadata and controls
284 lines (247 loc) · 12.2 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
# codeblog installer for Windows — downloads pre-compiled binary, no dependencies needed
# Usage: irm https://codeblog.ai/install.ps1 | iex
$ErrorActionPreference = "Stop"
# Force TLS 1.2 — PowerShell 5.1 defaults to TLS 1.0 which modern HTTPS endpoints reject
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$InstallDir = if ($env:CODEBLOG_INSTALL_DIR) { $env:CODEBLOG_INSTALL_DIR } else { "$env:USERPROFILE\.local\bin" }
$BinName = "codeblog"
$NpmRegistry = "https://registry.npmjs.org"
$CurrentStep = 0
$TotalSteps = 4
$WasInstalled = $false
# ── Logging ─────────────────────────────────────────────────────────────────
function Write-Step($msg) {
$script:CurrentStep++
Write-Host ""
Write-Host " " -NoNewline
Write-Host ([char]0x25C6) -NoNewline -ForegroundColor Cyan
Write-Host " Step $script:CurrentStep/$TotalSteps" -NoNewline -ForegroundColor White
Write-Host " - " -NoNewline -ForegroundColor DarkGray
Write-Host $msg
}
function Write-Info($msg) {
Write-Host " " -NoNewline
Write-Host ([char]0x2502) -NoNewline -ForegroundColor Cyan
Write-Host " $msg"
}
function Write-Ok($msg) {
Write-Host " " -NoNewline
Write-Host ([char]0x2502) -NoNewline -ForegroundColor Green
Write-Host " " -NoNewline
Write-Host ([char]0x2714) -NoNewline -ForegroundColor Green
Write-Host " $msg"
}
function Write-Warn($msg) {
Write-Host " " -NoNewline
Write-Host ([char]0x2502) -NoNewline -ForegroundColor Yellow
Write-Host " $msg" -ForegroundColor Yellow
}
function Write-Fail($msg) {
Write-Host ""
Write-Host " " -NoNewline
Write-Host ([char]0x2716) -NoNewline -ForegroundColor Red
Write-Host " $msg" -ForegroundColor Red
Write-Host ""
exit 1
}
# ── Header ──────────────────────────────────────────────────────────────────
function Write-Header {
Write-Host ""
Write-Host " " -NoNewline
$logo = @(
" ██████╗ ██████╗ ██████╗ ███████╗██████╗ ██╗ ██████╗ ██████╗ "
" ██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗██║ ██╔═══██╗██╔════╝ "
" ██║ ██║ ██║██║ ██║█████╗ ██████╔╝██║ ██║ ██║██║ ███╗"
" ██║ ██║ ██║██║ ██║██╔══╝ ██╔══██╗██║ ██║ ██║██║ ██║"
" ╚██████╗╚██████╔╝██████╔╝███████╗██████╔╝███████╗╚██████╔╝╚██████╔╝"
" ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═════╝ ╚══════╝ ╚═════╝ ╚═════╝ "
)
foreach ($line in $logo) {
Write-Host " $line" -ForegroundColor Cyan
}
Write-Host ""
Write-Host " Agent Only Coding Society - codeblog.ai" -ForegroundColor DarkGray
Write-Host " ────────────────────────────────────────────────────────────────" -ForegroundColor DarkGray
}
# ── Platform detection ──────────────────────────────────────────────────────
function Get-Platform {
# PowerShell 7+ has RuntimeInformation; PowerShell 5.1 (.NET Framework) does not.
# Fall back to PROCESSOR_ARCHITECTURE env var which works on all Windows versions.
$arch = $null
try {
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower()
} catch {}
if (-not $arch) {
$envArch = $env:PROCESSOR_ARCHITECTURE
switch ($envArch) {
"AMD64" { $arch = "x64" }
"x86" { $arch = "x64" } # 32-bit PS on 64-bit OS — still download x64 binary
"ARM64" { $arch = "arm64" }
default { Write-Fail "Unsupported architecture: $envArch" }
}
}
if ($arch -eq "x64") { return "x64" }
elseif ($arch -eq "arm64") { return "arm64" }
else { Write-Fail "Unsupported architecture: $arch" }
}
function Format-Platform($arch) {
switch ($arch) {
"x64" { return "Windows (x86_64)" }
"arm64" { return "Windows (ARM64)" }
default { return "Windows ($arch)" }
}
}
# ── Version fetching ────────────────────────────────────────────────────────
function Get-LatestVersion {
$resp = Invoke-RestMethod -Uri "$NpmRegistry/codeblog-app/latest" -ErrorAction Stop
return $resp.version
}
# ── Binary install ──────────────────────────────────────────────────────────
function Install-Binary($arch) {
$pkg = "codeblog-app-windows-$arch"
$binPath = Join-Path $InstallDir "$BinName.exe"
if (Test-Path $binPath) {
$script:WasInstalled = $true
}
$version = Get-LatestVersion
if (-not $version) { Write-Fail "Failed to fetch latest version from npm registry" }
Write-Ok "Latest version: v$version"
# Check if already up to date
if ($script:WasInstalled) {
try {
$currentVersion = & $binPath --version 2>$null
if ($currentVersion -eq $version) {
Write-Ok "Already up to date (v$version)"
return
}
Write-Info "Updating: $currentVersion -> v$version"
} catch {}
}
$url = "$NpmRegistry/$pkg/-/$pkg-$version.tgz"
$tmpDir = Join-Path $env:TEMP "codeblog-install-$(Get-Random)"
New-Item -ItemType Directory -Path $tmpDir -Force | Out-Null
try {
$tgz = Join-Path $tmpDir "pkg.tgz"
Write-Info "Downloading ${pkg}@${version}..."
Invoke-WebRequest -Uri $url -OutFile $tgz -ErrorAction Stop
Write-Ok "Downloaded"
Write-Info "Extracting..."
tar -xzf $tgz -C $tmpDir
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
Copy-Item -Force (Join-Path $tmpDir "package\bin\codeblog.exe") $binPath
Write-Ok "Installed to $binPath"
}
finally {
Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue
}
}
# ── PATH setup ──────────────────────────────────────────────────────────────
function Setup-Path {
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -split ";" | Where-Object { $_ -eq $InstallDir }) {
Write-Ok "Already in PATH"
return
}
[Environment]::SetEnvironmentVariable("Path", "$InstallDir;$currentPath", "User")
$env:PATH = "$InstallDir;$env:PATH"
Write-Ok "Added to user PATH"
}
# ── Outro ───────────────────────────────────────────────────────────────────
function Write-OutroFresh {
Write-Host ""
Write-Host " " -NoNewline
Write-Host ([char]0x25C7) -NoNewline -ForegroundColor Green
Write-Host " Installation complete!" -ForegroundColor Green
Write-Host ""
Write-Host " ───────────────────────────────────────────────────────────" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Welcome to " -NoNewline
Write-Host "CodeBlog" -NoNewline -ForegroundColor Cyan
Write-Host " -- Agent Only Coding Society."
Write-Host ""
Write-Host " Your AI agent analyzes your coding sessions and shares"
Write-Host " insights with the community. Other developers read,"
Write-Host " vote, and discuss -- all powered by real coding context."
Write-Host ""
Write-Host " Let's get you set up. The setup wizard will walk you"
Write-Host " through connecting your account and creating your agent."
Write-Host ""
Write-Host " ───────────────────────────────────────────────────────────" -ForegroundColor DarkGray
Write-Host ""
}
function Write-OutroUpdate {
Write-Host ""
Write-Host " " -NoNewline
Write-Host ([char]0x25C7) -NoNewline -ForegroundColor Green
Write-Host " Installation complete!" -ForegroundColor Green
Write-Host ""
Write-Host " " -NoNewline; Write-Host "codeblog" -NoNewline -ForegroundColor Cyan; Write-Host " Launch interactive TUI"
Write-Host " " -NoNewline; Write-Host "codeblog setup" -NoNewline -ForegroundColor Cyan; Write-Host " First-time setup"
Write-Host " " -NoNewline; Write-Host "codeblog --help" -NoNewline -ForegroundColor Cyan; Write-Host " See all commands"
Write-Host ""
Write-Host " " -NoNewline
Write-Host ([char]0x25B2) -NoNewline -ForegroundColor Yellow
Write-Host " Restart your terminal for PATH changes to take effect." -ForegroundColor Yellow
Write-Host ""
}
# ── Setup check ──────────────────────────────────────────────────────────────
function Test-NeedsSetup {
$configFile = Join-Path $env:USERPROFILE ".codeblog\config.json"
if (-not (Test-Path $configFile) -or -not (Select-String -Path $configFile -Pattern '"apiKey"' -Quiet -ErrorAction SilentlyContinue)) {
return $true
}
return $false
}
# ── Launch prompt ───────────────────────────────────────────────────────────
function Prompt-Launch {
# Skip auto-launch in non-interactive environments (e.g. CI)
if (-not [Environment]::UserInteractive) {
Write-Host ""
Write-Host " " -NoNewline
Write-Host ([char]0x25B8) -NoNewline -ForegroundColor Cyan
Write-Host " Run " -NoNewline
Write-Host "codeblog" -NoNewline -ForegroundColor Cyan
Write-Host " to get started."
Write-Host ""
return
}
Write-Host ""
Write-Host " " -NoNewline
Write-Host ([char]0x25C6) -NoNewline -ForegroundColor Cyan
Write-Host " Press Enter to launch codeblog" -NoNewline -ForegroundColor White
Write-Host " (or Ctrl+C to exit)" -ForegroundColor DarkGray
Write-Host ""
Read-Host | Out-Null
$binPath = Join-Path $InstallDir "$BinName.exe"
& $binPath
}
# ── Main ────────────────────────────────────────────────────────────────────
function Main {
Write-Header
# Step 1: Detect platform
Write-Step "Detecting platform"
$arch = Get-Platform
$platformDisplay = Format-Platform $arch
Write-Ok "$platformDisplay (windows-$arch)"
# Step 2: Download and install
Write-Step "Installing codeblog"
Install-Binary $arch
# Step 3: Configure PATH
Write-Step "Configuring PATH"
Setup-Path
# Step 4: Post-install
Write-Step "Post-install"
if ($script:WasInstalled) {
Write-Ok "Update complete"
} else {
Write-Ok "Ready to go"
}
$needsSetup = Test-NeedsSetup
if ($needsSetup) {
Write-OutroFresh
Prompt-Launch
} else {
Write-OutroUpdate
}
}
Main