Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
497 lines (464 loc) · 24.8 KB
/
Copy pathinstall.ps1
File metadata and controls
497 lines (464 loc) · 24.8 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# Installs Rackside on Windows for the person running this script. It needs no administrator
# rights. (On Linux and macOS, use install.sh.)
#
# powershell -ExecutionPolicy ByPass -c "irm https://github.com/nprev-dev/rackside/releases/latest/download/install.ps1 | iex"
#
# Each release comes with its own copy of this script, which installs that release. Run from
# anywhere else (the repository itself), it hands over to the installer of the latest release.
#
# Everything goes into one folder, rackside in your user folder: the program, the Python it
# runs on, your settings, what it saves, its log, and a script that removes it all again
# (double-click uninstall.cmd).
#
# The one thing outside that folder is the entry among the programs Windows starts when you sign
# in, because Windows keeps those in the registry. PATH is not changed.
#
# To pass options, run it as a block instead:
#
# & ([scriptblock]::Create((irm https://github.com/nprev-dev/rackside/releases/latest/download/install.ps1))) -Lan
#
# -Lan let other machines on the network open the page (the default is this machine only)
# -Port N listen on port N (default 8787)
# -Dir PATH use another folder than rackside in your user folder
# -NoStartup install only; do not set it up to start by itself
# -Uninstall remove it: the start-up entry and the folder with everything in it
# -Version X install release X (for example 0.1.0) instead of the latest one
# -Ref NAME install the code of a branch, tag or commit instead of a release ("main" is the
# newest code, not yet released)
#
# The program is fetched with uv (https://docs.astral.sh/uv/), of which the folder gets its own copy.
param(
[switch]$Lan,
[int]$Port = 0,
[string]$Dir = "",
[switch]$NoStartup,
[switch]$Uninstall,
[string]$Version = "",
[string]$Ref = "",
# For trying out a copy that is not on GitHub: a folder, a built package or an address.
[string]$Source = "",
[switch]$Help
)
$Rackside = @{
# RACKSIDE_REPO is for trying this script against a stand-in for GitHub (see tests/fake_github.py).
Repo = $(if ($env:RACKSIDE_REPO) { $env:RACKSIDE_REPO } else { "https://github.com/nprev-dev/rackside" })
# The release this copy of the script installs. Empty in the repository; filled in when a release
# is built (see .github/workflows/release.yml).
Release = ""
Name = "rackside"
# The name of the entry among the programs Windows starts at sign-in.
Entry = "Rackside"
RunKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
# A file of this name marks a folder as made by this script. The dashboard looks for it too
# (rack_dashboard/paths.py), and nothing is ever deleted from a folder without it.
Marker = ".rackside"
# The Python the dashboard is installed with: one the tests run on, not whatever came out last.
Python = "3.14"
}
# Rackside was called Rack Dashboard up to version 0.1.0. An install from then is taken over: its
# start-up entry is replaced, and its folder, settings and history included, becomes Rackside's.
$RacksideBefore = @{
Name = "rack-dashboard"
Entry = "RackDashboard"
Marker = ".rack-dashboard"
}
# The script that takes everything away again. It is written into the folder, and it is also what
# -Uninstall runs, so there is one way of removing things and not two.
$RacksideUninstaller = @'
# Removes Rackside: the entry that starts it when you sign in, and this folder with
# everything in it (the program, its Python, your settings, the saved history and the log).
#
# Double-click uninstall.cmd beside this file, or run:
#
# powershell -ExecutionPolicy Bypass -File uninstall.ps1
param([string]$Folder = "", [switch]$Wait)
$ErrorActionPreference = "Stop"
$entry = "Rackside"
$runKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
$marker = ".rackside"
try {
# Told a folder, that one; otherwise the folder this script is in.
if (-not $Folder) { $Folder = $PSScriptRoot }
$Folder = $Folder.TrimEnd("\")
$inside = $Folder + "\"
$removed = $false
$started = (Get-ItemProperty -Path $runKey -Name $entry -ErrorAction SilentlyContinue).$entry
if ($started) {
$program = "$started".Trim('"')
# Ours to remove if it starts the copy in this folder, or a copy that is no longer there.
if ($program.StartsWith($inside, [StringComparison]::OrdinalIgnoreCase) -or -not (Test-Path -LiteralPath $program)) {
Remove-ItemProperty -Path $runKey -Name $entry
Write-Host "Removed the start-up entry."
$removed = $true
}
}
if (-not (Test-Path -LiteralPath $Folder)) {
if (-not $removed) { Write-Host "Rackside is not installed (no folder at $Folder)." }
} elseif (-not (Test-Path -LiteralPath (Join-Path $Folder $marker) -PathType Leaf)) {
throw "$Folder was not made by the Rackside installer, so it was left alone."
} else {
# Windows will not delete the files of a program that is running. Everything the dashboard
# runs is inside its folder: the command, and the Python that does the work.
$running = @(Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.Id -ne $PID -and $_.Path -and $_.Path.StartsWith($inside, [StringComparison]::OrdinalIgnoreCase) })
foreach ($process in $running) {
try { Stop-Process -Id $process.Id -Force -ErrorAction Stop } catch { }
}
foreach ($process in $running) {
try { Wait-Process -Id $process.Id -Timeout 10 -ErrorAction Stop } catch { }
}
# Nor a folder that something is standing in.
if ((Get-Location).Path.StartsWith($Folder, [StringComparison]::OrdinalIgnoreCase)) { Set-Location -LiteralPath $env:USERPROFILE }
[Environment]::CurrentDirectory = $env:TEMP
$tries = 0
while (Test-Path -LiteralPath $Folder) {
try {
Remove-Item -LiteralPath $Folder -Recurse -Force -ErrorAction Stop
} catch {
$tries += 1
if ($tries -ge 5) { throw "could not remove $Folder (is something in it still open?): $($_.Exception.Message)" }
Start-Sleep -Seconds 1
}
}
Write-Host "Removed $Folder and everything in it. Nothing of Rackside is left on this machine."
}
} catch {
Write-Host "uninstall: $($_.Exception.Message)"
if ($Wait) { Start-Sleep -Seconds 8 }
throw
}
# Started by a double-click, the window would close before anyone could read the above.
if ($Wait) { Start-Sleep -Seconds 4 }
'@
# What a double-click runs. It steps out of the folder first. The "(goto)" ends this file's turn
# while the rest of the line still runs: without it, Windows would come back to read the next line
# of a file that has just been deleted, and complain.
$RacksideUninstallerCmd = @'
@echo off
rem Removes Rackside: the start-up entry and this folder with everything in it.
cd /d "%TEMP%" & (goto) 2>nul & powershell -NoProfile -ExecutionPolicy Bypass -File "%~dp0uninstall.ps1" -Wait
'@
# Runs a program and hands back its exit code and what it printed. Windows PowerShell treats
# anything a program writes to its error stream as a failure of the script; here it is just text.
function Invoke-RackTool {
param([string]$Program, [string[]]$Arguments)
$ErrorActionPreference = "Continue"
$printed = & $Program @Arguments 2>&1 | ForEach-Object { "$_" }
return [pscustomobject]@{ Code = $LASTEXITCODE; Printed = ($printed -join "`n") }
}
# The folder the start-up entry on this machine points to, if it is one of ours.
function Get-RackInstalledFolder {
$started = (Get-ItemProperty -Path $Rackside.RunKey -Name $Rackside.Entry -ErrorAction SilentlyContinue).($Rackside.Entry)
if (-not $started) { return $null }
$program = "$started".Trim('"')
$tail = "\bin\$($Rackside.Name)w.exe"
if (-not $program.EndsWith($tail, [StringComparison]::OrdinalIgnoreCase)) { return $null }
$folder = $program.Substring(0, $program.Length - $tail.Length)
if (Test-Path -LiteralPath (Join-Path $folder $Rackside.Marker) -PathType Leaf) { return $folder }
return $null
}
# The folder of an install from before the rename, if this machine has one.
function Get-RackOldFolder {
$before = $RacksideBefore
$started = (Get-ItemProperty -Path $Rackside.RunKey -Name $before.Entry -ErrorAction SilentlyContinue).($before.Entry)
$folder = $null
if ($started) {
$program = "$started".Trim('"')
$tail = "\bin\$($before.Name)w.exe"
if ($program.EndsWith($tail, [StringComparison]::OrdinalIgnoreCase)) { $folder = $program.Substring(0, $program.Length - $tail.Length) }
}
if (-not $folder) { $folder = Join-Path $env:USERPROFILE $before.Name }
if (Test-Path -LiteralPath (Join-Path $folder $before.Marker) -PathType Leaf) { return $folder }
return $null
}
# Stops a running dashboard: Windows will not replace the files of a program that is running.
function Stop-Rackside {
param([string]$Folder)
$inside = $Folder + "\"
$running = @(Get-Process -ErrorAction SilentlyContinue | Where-Object { $_.Id -ne $PID -and $_.Path -and $_.Path.StartsWith($inside, [StringComparison]::OrdinalIgnoreCase) })
foreach ($process in $running) {
try { Stop-Process -Id $process.Id -Force -ErrorAction Stop } catch { }
}
foreach ($process in $running) {
try { Wait-Process -Id $process.Id -Timeout 10 -ErrorAction Stop } catch { }
}
return $running.Count
}
# Sets a KEY=value line in the settings file, replacing an earlier one for the same key.
function Set-RackSetting {
param([string]$File, [string]$Key, [string]$Value)
$lines = @()
if (Test-Path -LiteralPath $File) { $lines = @([IO.File]::ReadAllLines($File)) }
$found = $false
$lines = @($lines | ForEach-Object { if ($_.StartsWith("$Key=")) { $found = $true; "$Key=$Value" } else { $_ } })
if (-not $found) { $lines += "$Key=$Value" }
[IO.File]::WriteAllLines($File, [string[]]$lines)
}
function Test-RackAnswering {
param([int]$OnPort)
try {
$null = Invoke-WebRequest -UseBasicParsing -TimeoutSec 3 -Uri "http://127.0.0.1:$OnPort/api/snapshot"
return $true
} catch {
return $false
}
}
# Runs the installer of another release with the same options. A release's installer installs that
# release, so script and program always come from the same release and fit together.
function Invoke-RackRelease {
param([string]$Url, [string]$What, [string]$Folder)
try {
$text = "$(Invoke-RestMethod -UseBasicParsing -Uri $Url)"
} catch {
throw "could not download the installer of $What ($Url). For the newest code instead of a release, add: -Ref main"
}
if ($text -notmatch '(?m)^\s*Release = "\d') { throw "what came from $Url is not the installer of a release" }
$options = @{ Dir = $Folder }
if ($Lan) { $options.Lan = $true }
if ($Port) { $options.Port = $Port }
if ($NoStartup) { $options.NoStartup = $true }
& ([scriptblock]::Create($text)) @options
}
function Install-Rackside {
$ErrorActionPreference = "Stop"
# The progress bar of Windows PowerShell slows a download down many times over.
$ProgressPreference = "SilentlyContinue"
$name = $Rackside.Name
$repo = $Rackside.Repo
$release = $Rackside.Release
if ($Help) {
Write-Host @"
Installs Rackside for the person running it, into one folder. No administrator rights needed.
-Lan let other machines on the network open the page (default: this machine only)
-Port N listen on port N (default 8787)
-Dir PATH use another folder than rackside in your user folder
-NoStartup install only; do not set it up to start by itself
-Uninstall remove it: the start-up entry and the folder with everything in it
-Version X install release X (for example 0.1.0) instead of the latest one
-Ref NAME install the code of a branch, tag or commit instead of a release
("main" is the newest code, not yet released)
"@
return
}
if ($PSVersionTable.PSVersion.Major -ge 6 -and -not $IsWindows) {
throw "this script is for Windows; on Linux and macOS use install.sh (see the readme)"
}
if ($Port -ne 0 -and ($Port -lt 1 -or $Port -gt 65535)) {
throw "-Port needs a number from 1 to 65535"
}
$wanted = $Version.TrimStart("v")
if ($wanted -and $wanted -notmatch '^\d+(\.\d+)*$') { throw "-Version needs a release number, like 0.1.0" }
if ($wanted -and $Ref) { throw "-Version and -Ref cannot be used together" }
# Older copies of Windows PowerShell do not offer the encryption GitHub asks for unless told to.
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
# Which folder. One that the start-up entry already points to is the one meant, unless told otherwise.
$existing = Get-RackInstalledFolder
$old = Get-RackOldFolder
if ($Dir) {
$folder = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Dir)
} elseif ($existing) {
$folder = $existing
} elseif ($old -and $old -ne (Join-Path $env:USERPROFILE $RacksideBefore.Name)) {
# An install from before the rename keeps a folder of its own; one in the old usual place
# moves to the new usual place.
$folder = $old
} else {
$folder = Join-Path $env:USERPROFILE $name
}
$folder = $folder.TrimEnd("\")
if (-not $folder -or $folder -eq $env:USERPROFILE.TrimEnd("\") -or $folder -eq [IO.Path]::GetPathRoot($folder).TrimEnd("\")) {
throw "choose a folder of its own for -Dir, not $folder\"
}
if ($Uninstall) {
if ($old -and (Test-Path -LiteralPath (Join-Path $old "uninstall.ps1"))) {
Write-Host "Removing the install from before the rename, in $old ..."
& ([scriptblock]::Create((Get-Content -Raw -LiteralPath (Join-Path $old "uninstall.ps1")))) -Folder $old
}
$started = Get-ItemProperty -Path $Rackside.RunKey -Name $Rackside.Entry -ErrorAction SilentlyContinue
if (-not $old -or (Test-Path -LiteralPath $folder) -or $started) {
& ([scriptblock]::Create($RacksideUninstaller)) -Folder $folder
}
return
}
# What to install: a release, or with -Ref the code of a branch, tag or commit. A release other
# than this script's own is installed by that release's installer.
if (-not $Source -and -not $Ref) {
if (-not $wanted -and -not $release) {
Invoke-RackRelease "$repo/releases/latest/download/install.ps1" "the latest release" $folder
return
}
if ($wanted -and $wanted -ne $release) {
Invoke-RackRelease "$repo/releases/download/v$wanted/install.ps1" "release $wanted" $folder
return
}
$Source = "$name @ $repo/releases/download/v$release/$name-$release-py3-none-any.whl"
} elseif (-not $Source) {
$Source = "$name @ $repo/archive/$Ref.tar.gz"
}
if ($old) {
if ($old -ne $folder -and (Test-Path -LiteralPath $folder) -and @(Get-ChildItem -LiteralPath $folder -Force).Count -gt 0) {
throw "Rack Dashboard (Rackside's name before 0.2.0) is installed in $old, and $folder is already in use, so it cannot be moved there. Remove one of the two first."
}
Write-Host "Taking over the install from before the rename (Rack Dashboard, in $old) ..."
$null = Stop-Rackside $old
if (Get-ItemProperty -Path $Rackside.RunKey -Name $RacksideBefore.Entry -ErrorAction SilentlyContinue) {
Remove-ItemProperty -Path $Rackside.RunKey -Name $RacksideBefore.Entry
}
if ($old -ne $folder) {
if (Test-Path -LiteralPath $folder) { Remove-Item -LiteralPath $folder -Force }
$parent = Split-Path -Parent $folder
if (-not (Test-Path -LiteralPath $parent)) { $null = New-Item -ItemType Directory -Force -Path $parent }
$tries = 0
while (Test-Path -LiteralPath $old) {
try {
Move-Item -LiteralPath $old -Destination $folder -ErrorAction Stop
} catch {
# Files of a program that has just been stopped can stay locked for a moment.
$tries += 1
if ($tries -ge 5) { throw "could not move $old to ${folder}: $($_.Exception.Message)" }
Start-Sleep -Seconds 1
}
}
}
# What only belonged to the old name. Everything else, settings and history first of all, stays.
foreach ($leftover in "tools\$($RacksideBefore.Name)", "bin\$($RacksideBefore.Name).exe", "bin\$($RacksideBefore.Name)w.exe", $RacksideBefore.Marker) {
Remove-Item -LiteralPath (Join-Path $folder $leftover) -Recurse -Force -ErrorAction SilentlyContinue
}
$oldLog = Join-Path $folder "$($RacksideBefore.Name).log"
if (Test-Path -LiteralPath $oldLog) { Move-Item -LiteralPath $oldLog -Destination (Join-Path $folder "$name.log") -Force }
[IO.File]::WriteAllText((Join-Path $folder $Rackside.Marker), "")
}
if ($Dir -and $existing -and ($existing -ne $folder) -and (Test-Path -LiteralPath $existing)) {
throw "Rackside is already installed in $existing. Remove it first (uninstall.cmd in that folder), or leave out -Dir to update it."
}
$marker = Join-Path $folder $Rackside.Marker
if ((Test-Path -LiteralPath $folder) -and -not (Test-Path -LiteralPath $marker -PathType Leaf)) {
if (-not (Test-Path -LiteralPath $folder -PathType Container) -or @(Get-ChildItem -LiteralPath $folder -Force).Count -gt 0) {
throw "$folder exists and was not made by this installer. Choose another folder with -Dir."
}
}
$null = New-Item -ItemType Directory -Force -Path $folder
[IO.File]::WriteAllText($marker, "Rackside is installed in this folder. Everything it uses is in here; uninstall.cmd removes it.`r`n")
[IO.File]::WriteAllText((Join-Path $folder "uninstall.ps1"), (($RacksideUninstaller -replace "`r?`n", "`r`n") + "`r`n"), [Text.Encoding]::ASCII)
[IO.File]::WriteAllText((Join-Path $folder "uninstall.cmd"), (($RacksideUninstallerCmd -replace "`r?`n", "`r`n") + "`r`n"), [Text.Encoding]::ASCII)
# uv is told through the environment where to put things, its temporary files included: those
# go into the folder as well and are removed at the end. What was set before is put back
# afterwards, so that nothing lingers in the PowerShell this was pasted into.
$bin = Join-Path $folder "bin"
$scratchFolder = Join-Path $folder ".tmp"
Remove-Item -LiteralPath $scratchFolder -Recurse -Force -ErrorAction SilentlyContinue
$null = New-Item -ItemType Directory -Force -Path $scratchFolder
$told = @{
UV_UNMANAGED_INSTALL = $bin
UV_PYTHON_INSTALL_DIR = Join-Path $folder "python"
UV_TOOL_DIR = Join-Path $folder "tools"
UV_TOOL_BIN_DIR = $bin
TMP = $scratchFolder
TEMP = $scratchFolder
}
$before = @{}
foreach ($key in $told.Keys) {
$before[$key] = [Environment]::GetEnvironmentVariable($key, "Process")
[Environment]::SetEnvironmentVariable($key, $told[$key], "Process")
}
try {
# 1. uv, which fetches Python and the dashboard. The folder gets its own copy, put there
# without touching PATH.
$uv = Join-Path $bin "uv.exe"
if (-not (Test-Path -LiteralPath $uv)) {
Write-Host "Fetching uv (the installer tool) from astral.sh ..."
$scratch = Join-Path $scratchFolder "uv-install.ps1"
try {
try {
Invoke-WebRequest -UseBasicParsing -Uri "https://astral.sh/uv/install.ps1" -OutFile $scratch
} catch {
throw "could not download uv from astral.sh: $($_.Exception.Message)"
}
$shell = (Get-Process -Id $PID).Path
$fetched = Invoke-RackTool $shell @("-NoProfile", "-ExecutionPolicy", "Bypass", "-File", $scratch)
if ($fetched.Code -ne 0 -or -not (Test-Path -LiteralPath $uv)) {
throw "could not install uv; see https://docs.astral.sh/uv/getting-started/installation/`n$($fetched.Printed)"
}
} finally {
Remove-Item -LiteralPath $scratch -ErrorAction SilentlyContinue
}
}
# 2. Python and the dashboard itself, both kept inside the folder. Nothing is left in a cache.
if ((Stop-Rackside $folder) -gt 0) { Write-Host "Stopped the dashboard that was running." }
$what = if ($Ref) { " (the code of $Ref, not a release)" } elseif ($release) { " $release" } else { "" }
Write-Host "Installing $name$what into $folder ..."
$python = Invoke-RackTool $uv @("python", "install", $Rackside.Python, "--no-bin", "--no-registry", "--no-cache", "--quiet")
if ($python.Code -ne 0) { throw "could not fetch Python $($Rackside.Python):`n$($python.Printed)" }
$installed = Invoke-RackTool $uv @("tool", "install", "--force", "--quiet", "--no-cache", "--managed-python", "--python", $Rackside.Python, $Source)
if ($installed.Code -ne 0) { throw "could not install ${name}:`n$($installed.Printed)" }
} finally {
foreach ($key in $told.Keys) { [Environment]::SetEnvironmentVariable($key, $before[$key], "Process") }
Remove-Item -LiteralPath $scratchFolder -Recurse -Force -ErrorAction SilentlyContinue
}
$command = Join-Path $bin "$name.exe"
# The same program without a console window, for running in the background.
$quiet = Join-Path $bin "${name}w.exe"
if (-not (Test-Path -LiteralPath $command) -or -not (Test-Path -LiteralPath $quiet)) {
throw "the $name command did not appear in $bin"
}
Write-Host "Installed $((Invoke-RackTool $command @('--version')).Printed.Trim())"
# 3. Settings: one file of KEY=value lines, which the dashboard reads as it starts. An earlier
# one is kept.
$settings = Join-Path $folder "env"
$log = Join-Path $folder "$name.log"
if (-not (Test-Path -LiteralPath $settings)) {
[IO.File]::WriteAllLines($settings, [string[]]@(
"# Settings for Rackside, one KEY=value per line. The readme lists them all.",
"# They take effect when the dashboard is next started."
))
}
if ($Lan) { Set-RackSetting $settings "DASH_HOST" "0.0.0.0" }
if ($Port -ne 0) { Set-RackSetting $settings "DASH_PORT" "$Port" }
$current = @([IO.File]::ReadAllLines($settings))
$listening = 8787
foreach ($line in $current) {
if ($line -match "^DASH_PORT=(\d+)\s*$") { $listening = [int]$Matches[1] }
}
if ($NoStartup) {
Write-Host "Not set up to start by itself. Start it with: $command"
Write-Host "To remove it: double-click uninstall.cmd in $folder"
return
}
# 4. Have Windows start it at sign-in, and start it now.
if (-not (Test-Path -Path $Rackside.RunKey)) { $null = New-Item -Path $Rackside.RunKey -Force }
Set-ItemProperty -Path $Rackside.RunKey -Name $Rackside.Entry -Value ('"{0}"' -f $quiet)
$since = Get-Date
Start-Process -FilePath $quiet
# 5. Is it answering? A first start takes a while: Windows looks every new program over.
$tries = 0
while (-not (Test-RackAnswering $listening)) {
$tries += 1
if ($tries -ge 40) {
$said = ""
if ((Test-Path -LiteralPath $log) -and (Get-Item -LiteralPath $log).LastWriteTime -ge $since.AddSeconds(-2)) {
$said = (@(Get-Content -LiteralPath $log -Tail 20) -join "`n")
}
# 10048 is the number Windows gives "that address is already in use".
if ($said -match "10048|address already in use") {
throw "port $listening is already used by another program. Choose another: run this again with -Port N"
}
throw "it was started but is not answering. Look at: $log"
}
Start-Sleep -Seconds 1
}
Write-Host ""
Write-Host "Rackside is running: http://127.0.0.1:$listening"
if ($current -match "^DASH_HOST=0\.0\.0\.0") {
$address = $null
try {
$address = @(Get-NetIPConfiguration -ErrorAction Stop | Where-Object { $_.IPv4DefaultGateway } | ForEach-Object { $_.IPv4Address.IPAddress })[0]
} catch { }
if ($address) { Write-Host "From other machines: http://${address}:$listening" }
Write-Host "Windows may ask whether to let it through the firewall; other machines cannot open the page until it is allowed."
} else {
Write-Host "Only this machine can open it. Run the installer again with -Lan to change that."
}
Write-Host "Everything is in $folder (settings: env, log: $name.log)."
Write-Host "To remove it: double-click uninstall.cmd in that folder."
Write-Host "It starts when you sign in to Windows (Task Manager, Startup apps, lists it)."
}
Install-Rackside