-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.ps1
More file actions
77 lines (63 loc) · 2.25 KB
/
Copy pathinstall.ps1
File metadata and controls
77 lines (63 loc) · 2.25 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
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
$RepoOwner = 'RobinWM'
$RepoName = 'ship-cli'
$ReleaseBaseUrl = "https://github.com/$RepoOwner/$RepoName/releases/latest/download"
$InstallDir = Join-Path $env:USERPROFILE '.ship\bin'
$TargetExe = Join-Path $InstallDir 'ship.exe'
$TempDir = Join-Path ([System.IO.Path]::GetTempPath()) ("ship-" + [System.Guid]::NewGuid().ToString('N'))
function Fail([string]$Message) {
Write-Error $Message
exit 1
}
if (-not [Environment]::Is64BitOperatingSystem) {
Fail 'ship does not support 32-bit Windows. Please use a 64-bit version of Windows.'
}
if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') {
Fail 'Windows ARM64 is not supported yet.'
}
$assetName = 'ship-windows-x64.exe'
$downloadUrl = "$ReleaseBaseUrl/$assetName"
$tempExe = Join-Path $TempDir $assetName
New-Item -ItemType Directory -Force -Path $TempDir | Out-Null
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
try {
Write-Output 'Installing ship...'
Invoke-WebRequest -Uri $downloadUrl -OutFile $tempExe -ErrorAction Stop
& $tempExe --help *> $null
if ($LASTEXITCODE -ne 0) {
Fail "Downloaded binary failed verification: $tempExe"
}
Copy-Item -Force $tempExe $TargetExe
$userPath = [Environment]::GetEnvironmentVariable('Path', 'User')
$installDirNormalized = [System.IO.Path]::GetFullPath($InstallDir)
$pathEntries = @()
if ($userPath) {
$pathEntries = $userPath.Split(';', [System.StringSplitOptions]::RemoveEmptyEntries)
}
$alreadyPresent = $pathEntries | Where-Object {
try {
[System.IO.Path]::GetFullPath($_) -eq $installDirNormalized
} catch {
$_ -eq $InstallDir
}
}
if (-not $alreadyPresent) {
$newUserPath = if ([string]::IsNullOrWhiteSpace($userPath)) {
$InstallDir
} else {
"$InstallDir;$userPath"
}
[Environment]::SetEnvironmentVariable('Path', $newUserPath, 'User')
Write-Output "⚠️ Added $InstallDir to your user PATH. Restart your terminal to use 'ship'."
}
Write-Output "✅ Installed ship to $TargetExe"
Write-Output "✅ Done! Run 'ship --help' in a new terminal."
}
finally {
if (Test-Path $TempDir) {
Remove-Item -Recurse -Force $TempDir -ErrorAction SilentlyContinue
}
}