-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
install.ps1
99 lines (84 loc) · 3.83 KB
/
install.ps1
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
function Install-ZVM {
param(
[string]$urlSuffix
);
$ZVMRoot = "${Home}\.zvm"
$ZVMSelf = mkdir -Force "${ZVMRoot}\self"
$ZVMBin = mkdir -Force "${ZVMRoot}\bin"
$Target = $urlSuffix
$URL = "https://github.com/tristanisham/zvm/releases/latest/download/$urlSuffix"
$ZipPath = "${ZVMSelf}\$Target"
$null = mkdir -Force $ZVMSelf
# curl.exe "-#SfLo" "$ZVMSelf/elevate.cmd" "https://raw.githubusercontent.com/tristanisham/zvm/master/bin/elevate.cmd" -s
#curl.exe "-#SfLo" "$ZVMSelf/elevate.vbs" "https://raw.githubusercontent.com/tristanisham/zvm/master/bin/elevate.vbs" -s
Remove-Item -Force $ZipPath -ErrorAction SilentlyContinue
curl.exe "-#SfLo" "$ZipPath" "$URL"
if ($LASTEXITCODE -ne 0) {
Write-Output "Install Failed - could not download $URL"
Write-Output "The command 'curl.exe $URL -o $ZipPath' exited with code ${LASTEXITCODE}`n"
exit 1
}
if (!(Test-Path $ZipPath)) {
Write-Output "Install Failed - could not download $URL"
Write-Output "The file '$ZipPath' does not exist. Did an antivirus delete it?`n"
exit 1
}
$UnzippedPath = $Target.Substring(0, $Target.Length - 4)
try {
$lastProgressPreference = $global:ProgressPreference
$global:ProgressPreference = 'SilentlyContinue';
Expand-Archive "$ZipPath" "$ZVMSelf" -Force
$global:ProgressPreference = $lastProgressPreference
if (!(Test-Path "${ZVMSelf}\$UnzippedPath\zvm.exe")) {
throw "The file '${ZVMSelf}\$UnzippedPath\zvm.exe' does not exist. Download is corrupt / Antivirus intercepted?`n"
}
}
catch {
Write-Output "Install Failed - could not unzip $ZipPath"
Write-Error $_
exit 1
}
Remove-Item "${ZVMSelf}\zvm.exe" -ErrorAction SilentlyContinue
Move-Item "${ZVMSelf}\$UnzippedPath\zvm.exe" "${ZVMSelf}\zvm.exe" -Force
Remove-Item "${ZVMSelf}\$Target" -Recurse -Force
Remove-Item ${ZVMSelf}\$UnzippedPath -Force
$null = "$(& "${ZVMSelf}\zvm.exe")"
if ($LASTEXITCODE -eq 1073741795) {
# STATUS_ILLEGAL_INSTRUCTION
Write-Output "Install Failed - zvm.exe is not compatible with your CPU.`n"
exit 1
}
if ($LASTEXITCODE -ne 0) {
Write-Output "Install Failed - could not verify zvm.exe"
Write-Output "The command '${ZVMSelf}\zvm.exe' exited with code ${LASTEXITCODE}`n"
exit 1
}
$C_RESET = [char]27 + "[0m"
$C_GREEN = [char]27 + "[1;32m"
Write-Output "${C_GREEN}ZVM${DisplayVersion} was installed successfully!${C_RESET}"
Write-Output "The binary is located at ${ZVMSelf}\zvm.exe`n"
$User = [System.EnvironmentVariableTarget]::User
$Path = [System.Environment]::GetEnvironmentVariable('Path', $User) -split ';'
$ZVMInstall = 'ZVM_INSTALL'
$ZVMInstallValue = [System.Environment]::GetEnvironmentVariable($ZVMInstall, [System.EnvironmentVariableTarget]::User)
if ($null -eq $ZVMInstallValue) {
[System.Environment]::SetEnvironmentVariable($ZVMInstall, $ZVMSelf, [System.EnvironmentVariableTarget]::User)
}
if ($Path -notcontains $ZVMSelf) {
$Path += $ZVMSelf
[System.Environment]::SetEnvironmentVariable('Path', $Path -join ';', $User)
}
if ($env:PATH -notcontains ";${ZVMSelf}") {
$env:PATH = "${env:Path};${ZVMSelf}"
}
if ($Path -notcontains $ZVMBin) {
$Path += $ZVMBin
[System.Environment]::SetEnvironmentVariable('Path', $Path -join ';', $User)
}
if ($env:PATH -notcontains ";${ZVMBin}") {
$env:PATH = "${env:Path};${ZVMBin}"
}
Write-Output "To get started, restart your terminal/editor, then type `"zvm`"`n"
}
$PROCESSOR_ARCH = $env:PROCESSOR_ARCHITECTURE.ToLower()
Install-ZVM "zvm-windows-$PROCESSOR_ARCH.zip"