Repository navigation
Expand file tree
/
Copy pathinstall.ps1
More file actions
66 lines (53 loc) · 1.76 KB
/
Copy pathinstall.ps1
File metadata and controls
66 lines (53 loc) · 1.76 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
#!/usr/bin/env pwsh
# Copyright 2018 the Deno authors. All rights reserved. MIT license.
# Copyright 2022 justjavac. All rights reserved. MIT license.
# TODO(everyone): Keep this script simple and easily auditable.
$ErrorActionPreference = 'Stop'
$DvmDir = $env:DVM_DIR
$BinDir = if ($DvmDir) {
"$DvmDir\bin"
} else {
"$Home\.dvm\bin"
}
$DvmZip = "$BinDir\dvm.zip"
$DvmExe = "$BinDir\dvm.exe"
$DvmExeOldName = "dvm.exe.old"
$DvmExeOld = "$BinDir\$DvmExeOldName"
# Detect processor architecture and select the correct binary
$Arch = $env:PROCESSOR_ARCHITECTURE
switch ($Arch) {
"ARM64" {
$DvmArch = "aarch64-pc-windows-msvc"
}
"AMD64" {
$DvmArch = "x86_64-pc-windows-msvc"
}
"x86" {
Write-Error "32-bit Windows is not supported by dvm."
exit 1
}
default {
Write-Warning "Unknown processor architecture '$Arch', falling back to x86_64."
$DvmArch = "x86_64-pc-windows-msvc"
}
}
$DvmUri = "https://github.com/justjavac/dvm/releases/latest/download/dvm-$DvmArch.zip"
if (!(Test-Path $BinDir)) {
New-Item $BinDir -ItemType Directory | Out-Null
}
curl.exe -Lo $DvmZip $DvmUri
# Remove the old dvm.exe.old if it exists
Remove-Item $DvmExeOld -ErrorAction SilentlyContinue
# You cant delete a file that is currently running, so rename it
Rename-Item -Path $DvmExe -NewName $DvmExeOldName -ErrorAction SilentlyContinue
tar.exe xf $DvmZip -C $BinDir
Remove-Item $DvmZip
$User = [EnvironmentVariableTarget]::User
$Path = [Environment]::GetEnvironmentVariable('Path', $User)
if (!(";$Path;".ToLower() -like "*;$BinDir;*".ToLower())) {
[Environment]::SetEnvironmentVariable('Path', "$Path;$BinDir", $User)
$Env:Path += ";$BinDir"
}
Write-Output "Dvm was installed successfully to $DvmExe"
& dvm doctor
Write-Output "Run 'dvm --help' to get started"