forked from vmware-archive/vsphere-storage-for-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-vdvs.ps1
134 lines (116 loc) · 4.06 KB
/
install-vdvs.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# Copyright 2017 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Installation Instructions
# ============================================================================
# Run the script with the plugin url as the parameter in a PowerShell session:
# PS C:\Users\Administrator> .\install-vdvs.ps1 <vdvs-download-url>
# ============================================================================
<#
.SYNOPSIS
Installation script for VMware vSphere Docker Volume Plugin.
.DESCRIPTION
This script helps to download, install, uninstall, and re-install VMware vSphere Docker Volume Plugin on your system.
.EXAMPLE
./install-vdvs.ps1 https://bintray.com/vmware/vDVS/download_file?file_path=docker-volume-vsphere.zip
.EXAMPLE
./install-vdvs.ps1 -uninstall
.LINK
https://vmware.github.io/docker-volume-vsphere/
#>
# Command line parameters
param (
[string] $uri,
[switch] $uninstall
)
# Define the constants
$svcName = "vdvs"
$svcDisplayName = "vSphere Docker Volume Service"
$svcDescription = "Enables user to run stateful containerized applications on top of VMware vSphere."
$installPath = "C:\Program Files\VMware\vmdkops"
$exePathName = $installPath + "\vdvs.exe"
$zipFileName = "docker-volume-vsphere.zip"
function Uninstall-Service([System.ServiceProcess.ServiceController]$svc) {
if ($svc.Status -eq "Running") {
echo "Stopping Windows service $svcName..."
Stop-Service -Name $svcName
}
echo "Deleting Windows service $svcName..."
sc.exe delete $svcName
echo "Deleting $installPath..."
Remove-Item -Path $installPath -Recurse -Force
echo "Windows service $svcName uninstalled successfully!"
}
# Check if vDVS plugin is already installed
$svc = Get-Service | Where-Object {$_.Name -eq $svcName}
# Handle uninstallation
if ($uninstall) {
if ($svc) {
$confirmUninstall = Read-Host "Do you really want to uninstall $svcName [Y/N]?"
if ($confirmUninstall -eq "Y") {
Uninstall-Service($svc)
}
} else {
echo "Windows service $svcName is not installed."
}
return
}
# Check URI parameter for installation process
if (! $uri) {
echo "Usage: install-vdvs.ps1 [[-uri] <String>] [-uninstall]"
return
}
# Handle reinstallation
if ($svc) {
echo "Windows service $svcName is already installed."
$reinstall = Read-Host "Do you want to reinstall $svcName [Y/N]?"
if ($reinstall -eq "Y") {
Uninstall-Service($svc)
} else {
return
}
}
# Download the vdvs binary
echo "Downloading from $uri..."
Invoke-WebRequest $uri -OutFile $zipFileName
if (! $?) {
echo "Failed to download from $uri."
return
}
# Extract to the installation folder
echo "Extracting $zipFileName into $installPath..."
Expand-Archive -Path $zipFileName -DestinationPath $installPath -Force
if (! $?) {
echo "Failed to extract $zipFileName into $installPath."
return
}
# Remove the archive after successful expanding
echo "Deleting $zipFileName..."
Remove-Item -Path $zipFileName -Force
# Install the vdvs plugin as a service
echo "Installing Windows service $svcName from $exePathName..."
New-Service -Name $svcName -BinaryPathName $exePathName -DisplayName $svcDisplayName -Description $svcDescription
if (! $?) {
echo "Failed to install Windows service $svcName."
return
}
# Start the vdvs service
echo "Starting Windows service $svcName..."
Start-Service -Name $svcName
if (! $?) {
echo "Failed to start Windows service $svcName."
return
}
# Show the running service
Get-Service -Name $svcName
echo "Windows service $svcName installed successfully!"