-
Notifications
You must be signed in to change notification settings - Fork 50
/
install.ps1
75 lines (59 loc) · 2.53 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
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$ErrorActionPreference = "Stop"
function downloadDvm([string] $dvmDir) {
$webClient = New-Object net.webclient
echo "Downloading dvm.ps1..."
$webClient.DownloadFile("https://howtowhale.github.io/dvm/downloads/latest/dvm.ps1", "$dvmDir\dvm.ps1")
echo "Downloading dvm.cmd..."
$webClient.DownloadFile("https://howtowhale.github.io/dvm/downloads/latest/dvm.cmd", "$dvmDir\dvm.cmd")
echo "Downloading dvm-helper.exe..."
$tmpDir = Join-Path $dvmDir .tmp
if( !(Test-Path $tmpDir) ) {
mkdir $tmpDir > $null
}
# Ensure dvm-helper directory exists
$dvmHelperDir = Join-Path $dvmDir dvm-helper
if( !(Test-Path $dvmHelperDir ) ) {
mkdir $dvmHelperDir > $null
}
# Detect x86 vs. x64
if( [System.Environment]::Is64BitOperatingSystem ) { $arch = "x86_64" } else { $arch = "i686"}
# Download latest release
$webClient.DownloadFile("https://howtowhale.github.io/dvm/downloads/latest/Windows/$arch/dvm-helper.exe", "$tmpDir\dvm-helper.exe")
$webClient.DownloadFile("https://howtowhale.github.io/dvm/downloads/latest/Windows/$arch/dvm-helper.exe.sha256", "$tmpDir\dvm-helper.exe.256")
# Verify the binary was downloaded successfully
$checksum = (cat $tmpDir\dvm-helper.exe.256).Split(' ')[0]
$hash = (Get-FileHash $tmpDir\dvm-helper.exe).Hash
if([string]::Compare($checksum, $hash, $true) -ne 0) {
$host.ui.WriteErrorLine("DANGER! The downloaded dvm-helper binary, $tmpDir\dvm-helper.exe, does not match its checksum!")
$host.ui.WriteErrorLine("CHECKSUM: $checksum")
$host.ui.WriteErrorLine("HASH: $hash")
return 1
}
mv -force "$tmpDir\dvm-helper.exe" "$dvmDir\dvm-helper\dvm-helper.exe"
}
function installDvm()
{
$dvmDir = $env:DVM_DIR
if( $dvmDir -eq $null ) {
$dvmDir = "$env:USERPROFILE\.dvm"
}
if( !(Test-Path $dvmDir) ) {
mkdir $dvmDir > $null
}
downloadDvm $dvmDir
echo ""
echo "Docker Version Manager (dvm) has been installed to $dvmDir"
echo ""
echo "PowerShell Users: Run the following command to start using dvm. Then add it to your PowerShell profile to complete the installation."
echo "`t. '$dvmDir\dvm.ps1'"
echo ""
echo "CMD Users: Run the first command to start using dvm. Then run the second command to add dvm to your PATH to complete the installation."
echo "`t1. PATH=%PATH%;$dvmDir"
echo "`t2. setx PATH `"%PATH%;$dvmDir`""
}
if($PSVersionTable -eq $null -or $PSVersionTable.PSVersion.Major -lt 4){
Write-Output "dvm requires PowerShell version 4 or higher."
Exit 1
}
installDvm