-
Notifications
You must be signed in to change notification settings - Fork 37
/
install.ps1
46 lines (35 loc) · 1.35 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
#!/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"
$DvmUri = "https://cdn.jsdelivr.net/gh/justjavac/dvm_releases@main/dvm-x86_64-pc-windows-msvc.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"
Invoke-Expression -Command "dvm doctor"
Write-Output "Run 'dvm --help' to get started"