Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
216 lines (193 loc) · 7.38 KB
/
Copy pathinstall.ps1
File metadata and controls
216 lines (193 loc) · 7.38 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
# Install the Dimo Host family (dimo-server, dimo-mcp,
# and the web bundle) from a GitHub Release.
#
# The desktop app is not installed by this script; it ships as an Electron
# installer with its own updater. Coding agents are not installed either —
# they live in your own environment (ADR-0060).
#
# irm https://raw.githubusercontent.com/DimoADE/Dimo/master/install.ps1 | iex
#
# Environment:
# DIMO_VERSION Install this version instead of the latest release.
# DIMO_PLATFORM Override platform detection (e.g. windows-x86_64).
# DIMO_GITHUB_REPO Source repository. Default DimoADE/Dimo.
# DIMO_HOST_FAMILY_BASE Override the download origin (no trailing slash).
# DIMO_INSTALL_DIR Where the `dimo.cmd` launcher goes. Default %LOCALAPPDATA%\Dimo\bin.
# DIMO_PRINT_PLAN Print the resolved platform and URLs, then exit.
$ErrorActionPreference = "Stop"
$Repo = if ($env:DIMO_GITHUB_REPO) { $env:DIMO_GITHUB_REPO } else { "DimoADE/Dimo" }
$CacheRoot = Join-Path $HOME ".dimo" "host-family"
$InstallDir = if ($env:DIMO_INSTALL_DIR) { $env:DIMO_INSTALL_DIR } else { Join-Path $env:LOCALAPPDATA "Dimo" "bin" }
# Kept in step with npx-cli/bin/release-assets.js by scripts/release-assets.test.js.
$SupportedPlatforms = @(
"linux-x86_64",
"linux-aarch64",
"darwin-aarch64",
"windows-x86_64",
"windows-aarch64"
)
function Fail([string]$Message) {
Write-Error "error: $Message"
exit 1
}
function Get-Platform {
if ($env:DIMO_PLATFORM) {
return $env:DIMO_PLATFORM
}
$os = if ($IsWindows -or $env:OS -eq "Windows_NT") {
"windows"
} elseif ($IsMacOS) {
"darwin"
} elseif ($IsLinux) {
"linux"
} else {
Fail "unsupported operating system. Supported: $($SupportedPlatforms -join ', ')"
return
}
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
$cpu = switch ($arch) {
"X64" { "x86_64" }
"Arm64" { "aarch64" }
default {
Fail "unsupported architecture: $arch. Supported: $($SupportedPlatforms -join ', ')"
return
}
}
return "$os-$cpu"
}
function Assert-SupportedPlatform([string]$Platform) {
if ($SupportedPlatforms -notcontains $Platform) {
Fail "unsupported platform: $Platform. Supported: $($SupportedPlatforms -join ', ')"
}
}
function Get-LatestTag {
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
if (-not $release.tag_name) {
Fail "could not resolve the latest release of $Repo"
}
return $release.tag_name
}
function Get-FileSha256([string]$Path) {
return (Get-FileHash -Algorithm SHA256 -Path $Path).Hash.ToLowerInvariant()
}
# Both the archive digest and the per-file SHA256SUMS inside it are checked.
# There is deliberately no flag to skip either: a mismatch means the bytes are
# not the published release, and installing them anyway defers the problem to
# runtime.
function Assert-Digest([string]$Path, [string]$Expected) {
$actual = Get-FileSha256 $Path
if ($actual -ne $Expected.ToLowerInvariant()) {
Fail "checksum mismatch for $(Split-Path $Path -Leaf): expected $Expected, got $actual"
}
}
function Assert-Sha256Sums([string]$Root) {
$sumsPath = Join-Path $Root "SHA256SUMS"
if (-not (Test-Path $sumsPath)) {
Fail "SHA256SUMS is missing under $Root"
}
$checked = 0
foreach ($line in Get-Content $sumsPath) {
if ($line -notmatch "^([a-fA-F0-9]{64}) (.+)$") {
continue
}
$relative = $Matches[2] -replace "^\./", ""
if ($relative -eq "SHA256SUMS") {
continue
}
$file = Join-Path $Root ($relative -replace "/", [IO.Path]::DirectorySeparatorChar)
if (-not (Test-Path $file)) {
Fail "Host family file missing after extract: $relative"
}
Assert-Digest $file $Matches[1]
$checked += 1
}
if ($checked -eq 0) {
Fail "SHA256SUMS in the archive contained no checksums"
}
}
function Write-Launcher([string]$FamilyRoot) {
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
$server = Join-Path $FamilyRoot "dimo-server.exe"
if (-not (Test-Path $server)) {
$server = Join-Path $FamilyRoot "dimo-server"
}
$cmd = Join-Path $InstallDir "dimo.cmd"
Set-Content -Path $cmd -Encoding ascii -Value "@echo off`r`n`"$server`" %*"
return $cmd
}
$platform = Get-Platform
Assert-SupportedPlatform $platform
if ($env:DIMO_VERSION) {
$tag = if ($env:DIMO_VERSION.StartsWith("v")) { $env:DIMO_VERSION } else { "v$($env:DIMO_VERSION)" }
} else {
$tag = Get-LatestTag
}
$version = $tag.TrimStart("v")
$archive = "Dimo-$version-$platform-server.tar.gz"
$baseUrl = if ($env:DIMO_HOST_FAMILY_BASE) {
$env:DIMO_HOST_FAMILY_BASE.TrimEnd("/")
} else {
"https://github.com/$Repo/releases/download/$tag"
}
$familyRoot = Join-Path $CacheRoot $tag $platform "family"
if ($env:DIMO_PRINT_PLAN) {
Write-Output "platform=$platform"
Write-Output "tag=$tag"
Write-Output "archive=$archive"
Write-Output "archive_url=$baseUrl/$archive"
Write-Output "checksum_url=$baseUrl/$archive.sha256"
Write-Output "family_root=$familyRoot"
exit 0
}
$temp = $null
try {
if (Test-Path (Join-Path $familyRoot "SHA256SUMS")) {
Write-Host "Dimo Host family $tag is already installed for $platform."
Assert-Sha256Sums $familyRoot
} else {
$temp = Join-Path ([IO.Path]::GetTempPath()) ("dimo-install-" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Path $temp | Out-Null
Write-Host "Downloading Dimo Host family $tag for $platform..."
$archivePath = Join-Path $temp $archive
$checksumPath = "$archivePath.sha256"
Invoke-WebRequest -Uri "$baseUrl/$archive" -OutFile $archivePath
Invoke-WebRequest -Uri "$baseUrl/$archive.sha256" -OutFile $checksumPath
$expected = ((Get-Content $checksumPath -Raw) -split "\s+")[0]
if (-not $expected) {
Fail "the published checksum file for $archive was empty"
}
Assert-Digest $archivePath $expected
$extract = Join-Path $temp "extract"
New-Item -ItemType Directory -Path $extract | Out-Null
tar -xzf $archivePath -C $extract
$unpacked = Join-Path $extract $platform
if (-not (Test-Path (Join-Path $unpacked "SHA256SUMS"))) {
$unpacked = $extract
}
if (-not (Test-Path (Join-Path $unpacked "SHA256SUMS"))) {
Fail "the archive did not contain SHA256SUMS"
}
Assert-Sha256Sums $unpacked
if (Test-Path $familyRoot) {
Remove-Item -Recurse -Force $familyRoot
}
New-Item -ItemType Directory -Force -Path (Split-Path $familyRoot) | Out-Null
Move-Item $unpacked $familyRoot
}
$launcher = Write-Launcher $familyRoot
Write-Host ""
Write-Host "Installed Dimo Host family $tag to $familyRoot"
Write-Host "Launcher: $launcher"
$onPath = ($env:PATH -split ";" | ForEach-Object { $_.TrimEnd("\") }) -contains $InstallDir.TrimEnd("\")
if ($onPath) {
Write-Host ""
Write-Host "Run ``dimo`` to start the server on http://127.0.0.1:17891"
} else {
Write-Host ""
Write-Host "Add $InstallDir to your PATH, then run ``dimo``."
}
} finally {
if ($temp -and (Test-Path $temp)) {
Remove-Item -Recurse -Force $temp
}
}