-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathponyup-init.ps1
More file actions
87 lines (75 loc) · 2.38 KB
/
ponyup-init.ps1
File metadata and controls
87 lines (75 loc) · 2.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
Param([string] $Prefix = "$env:LOCALAPPDATA\ponyup", [bool] $SetPath = $true)
$ErrorActionPreference = 'Stop'
# Detect system architecture
$Arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
if (-not $Arch) {
$Arch = $env:PROCESSOR_ARCHITECTURE
}
Write-Host "Detected architecture: $Arch"
if ($Arch -ieq 'amd64' -or $Arch -ieq 'x64')
{
$Arch = 'x86-64'
$PlatformStringArch = 'x86_64'
}
elseif ($Arch -ieq 'arm64')
{
$Arch = 'arm64'
$PlatformStringArch = 'arm64'
}
else
{
Write-Error "Unsupported architecture: $Arch. Supported architectures are: amd64, x64, arm64"
exit 1
}
$tempParent = [System.IO.Path]::GetTempPath()
$tempName = [System.Guid]::NewGuid()
$tempPath = (Join-Path $tempParent $tempName)
New-Item -ItemType Directory -Path $tempPath
$downloadUrl = 'https://dl.cloudsmith.io/public/ponylang/releases/raw/versions/latest'
$zipName = "ponyup-$Arch-pc-windows-msvc.zip"
$zipUrl = "$downloadUrl/$zipName"
$zipPath = "$tempPath\$zipName"
Write-Host "Downloading $zipUrl..."
Invoke-WebRequest -Uri $zipUrl -Outfile $zipPath
$ponyupPath = $Prefix
if (-not (Test-Path $ponyupPath)) {
New-Item -ItemType Directory -Path $ponyupPath
}
Write-Host "Unzipping to $ponyupPath..."
Expand-Archive -Force -Path $zipPath -DestinationPath $ponyupPath
$platform = "$PlatformStringArch-pc-windows-msvc"
Write-Host "Setting platform to $platform..."
Set-Content -Path "$ponyupPath\.platform" -Value $platform
$version = & "$ponyupPath\bin\ponyup" version
if ($version -match 'ponyup (\d+\.\d+\.\d+)') {
$lockStr = "ponyup-release-$($Matches[1])-$PlatformStringArch-windows"
Write-Host "Locking ponyup version to $lockStr..."
$lockPath = "$ponyupPath\.lock"
$newContent = @()
if (Test-Path $lockPath) {
$content = Get-Content -Path $lockPath
$content | Foreach-Object {
if ($_ -match '^ponyup') {
$newContent += $lockStr
}
else {
$newContent += $_
}
}
} else {
$newContent = @($lockStr)
}
Set-Content -Path "$ponyupPath\.lock" -Value $newContent
}
if ($SetPath) {
$binDir = "$ponyupPath\bin"
if (-not ($env:PATH -like "*$binDir*")) {
Write-Host "Adding $binDir to PATH; you will need to restart your terminal to use it."
$newPath = "$env:PATH;$binDir"
[Environment]::SetEnvironmentVariable("PATH", $newPath, 'User')
$env:PATH = $newPath
}
else {
Write-Host "$binDir is already in PATH"
}
}