Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tristanisham/zvm
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanisham committed Mar 4, 2024
2 parents 0f2b179 + 813737b commit 0ef7be7
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ function Install-ZVM {
);

$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 = "${ZVMBin}\$Target"
$ZipPath = "${ZVMSelf}\$Target"

$null = mkdir -Force $ZVMBin
$null = mkdir -Force $ZVMSelf
Remove-Item -Force $ZipPath -ErrorAction SilentlyContinue
curl.exe "-#SfLo" "$ZipPath" "$URL"
if ($LASTEXITCODE -ne 0) {
Expand All @@ -27,43 +28,51 @@ function Install-ZVM {
try {
$lastProgressPreference = $global:ProgressPreference
$global:ProgressPreference = 'SilentlyContinue';
Expand-Archive "$ZipPath" "$ZVMBin" -Force
Expand-Archive "$ZipPath" "$ZVMSelf" -Force
$global:ProgressPreference = $lastProgressPreference
if (!(Test-Path "${ZVMBin}\$UnzippedPath\zvm.exe")) {
throw "The file '${ZVMBin}\$UnzippedPath\zvm.exe' does not exist. Download is corrupt / Antivirus intercepted?`n"
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 "${ZVMBin}\zvm.exe" -ErrorAction SilentlyContinue
Move-Item "${ZVMBin}\$UnzippedPath\zvm.exe" "${ZVMBin}\zvm.exe" -Force
Remove-Item "${ZVMSelf}\zvm.exe" -ErrorAction SilentlyContinue
Move-Item "${ZVMSelf}\$UnzippedPath\zvm.exe" "${ZVMSelf}\zvm.exe" -Force

Remove-Item "${ZVMBin}\$Target" -Recurse -Force
Remove-Item ${ZVMBin}\$UnzippedPath -Force
Remove-Item "${ZVMSelf}\$Target" -Recurse -Force
Remove-Item ${ZVMSelf}\$UnzippedPath -Force

$null = "$(& "${ZVMBin}\zvm.exe")"
$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 '${ZVMBin}\zvm.exe' exited with code ${LASTEXITCODE}`n"
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 ${ZVMBin}\zvm.exe`n"
Write-Output "The binary is located at ${ZVMSelf}\zvm.exe`n"

$User = [System.EnvironmentVariableTarget]::User
$Path = [System.Environment]::GetEnvironmentVariable('Path', $User) -split ';'
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)
Expand Down

0 comments on commit 0ef7be7

Please sign in to comment.