-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
57 lines (51 loc) · 2.8 KB
/
Copy pathsetup.ps1
File metadata and controls
57 lines (51 loc) · 2.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
[CmdletBinding()]
param([string]$VsixPath)
$ErrorActionPreference = "Stop"
$repo = "bsambrone/robots4kids"
$scriptRoot = if ($PSScriptRoot) { $PSScriptRoot } else { (Get-Location).Path }
function Find-CodeCommand {
$command = Get-Command code -ErrorAction SilentlyContinue
if ($command) { return $command.Source }
$localCode = Join-Path $env:LOCALAPPDATA "Programs\Microsoft VS Code\bin\code.cmd"
if (Test-Path -LiteralPath $localCode) { return $localCode }
$systemCode = Join-Path $env:ProgramFiles "Microsoft VS Code\bin\code.cmd"
if (Test-Path -LiteralPath $systemCode) { return $systemCode }
$insidersCode = Join-Path $env:LOCALAPPDATA "Programs\Microsoft VS Code Insiders\bin\code-insiders.cmd"
if (Test-Path -LiteralPath $insidersCode) { return $insidersCode }
throw "Visual Studio Code was not found. Install it from https://code.visualstudio.com/ and run this script again."
}
if (-not $VsixPath) {
$localVsix = Get-ChildItem -Path (Join-Path $scriptRoot "artifacts") -Filter "*.vsix" -ErrorAction SilentlyContinue |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
if ($localVsix) {
$VsixPath = $localVsix.FullName
} else {
Write-Host "Downloading the newest Prime Robot Tools release..."
$release = Invoke-RestMethod "https://api.github.com/repos/$repo/releases/latest"
$asset = $release.assets | Where-Object name -Like "*.vsix" | Select-Object -First 1
if (-not $asset) { throw "The newest release does not contain a VSIX installer yet." }
$VsixPath = Join-Path $env:TEMP $asset.name
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $VsixPath
$checksumAsset = $release.assets | Where-Object name -EQ "$($asset.name).sha256" | Select-Object -First 1
if ($checksumAsset) {
$checksumPath = "$VsixPath.sha256"
Invoke-WebRequest -Uri $checksumAsset.browser_download_url -OutFile $checksumPath
$expectedHash = ((Get-Content -Raw -LiteralPath $checksumPath).Trim() -split "\s+")[0]
$actualHash = (Get-FileHash -LiteralPath $VsixPath -Algorithm SHA256).Hash
if ($actualHash -ne $expectedHash) {
throw "The downloaded extension did not match its published SHA-256 checksum."
}
}
}
}
$resolvedVsix = (Resolve-Path -LiteralPath $VsixPath).Path
$code = Find-CodeCommand
& $code --install-extension $resolvedVsix --force
if ($LASTEXITCODE -ne 0) {
throw "VS Code could not install the extension (exit code $LASTEXITCODE)."
}
Write-Host ""
Write-Host "Prime Robot Tools is installed." -ForegroundColor Green
Write-Host "Open VS Code, open a robot project folder, turn on the hub, and press F5."
Write-Host "If the hub does not have Pybricks firmware, follow the README's one-time firmware steps first."