Repository navigation
Expand file tree
/
Copy pathdockerInstall.psm1
More file actions
114 lines (97 loc) · 3.63 KB
/
Copy pathdockerInstall.psm1
File metadata and controls
114 lines (97 loc) · 3.63 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
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
function Install-ChocolateyPackage
{
param(
[Parameter(Mandatory=$true)]
[string]
$PackageName,
[Parameter(Mandatory=$false)]
[string]
$Executable,
[string[]]
$ArgumentList,
[switch]
$Cleanup,
[int]
$ExecutionTimeout = 2700,
[string]
$Version
)
if(-not(Get-Command -name Choco -ErrorAction SilentlyContinue))
{
Write-Verbose "Installing Chocolatey provider..." -Verbose
Invoke-WebRequest https://chocolatey.org/install.ps1 -UseBasicParsing | Invoke-Expression
}
Write-Verbose "Installing $PackageName..." -Verbose
$extraCommand = @()
if($Version)
{
$extraCommand += '--version', $version
}
choco install -y $PackageName --no-progress --execution-timeout=$ExecutionTimeout $ArgumentList $extraCommands
if($executable)
{
Write-Verbose "Verifing $Executable is in path..." -Verbose
$exeSource = $null
$exeSource = Get-ChildItem -path "$env:ProgramFiles\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
if(!$exeSource)
{
Write-Verbose "Falling back to x86 program files..." -Verbose
$exeSource = Get-ChildItem -path "${env:ProgramFiles(x86)}\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
}
# Don't search the chocolatey program data until more official locations have been searched
if(!$exeSource)
{
Write-Verbose "Falling back to chocolatey..." -Verbose
$exeSource = Get-ChildItem -path "$env:ProgramData\chocolatey\$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
}
# all obvious locations are exhausted, use brute force and search from the root of the filesystem
if(!$exeSource)
{
Write-Verbose "Falling back to the root of the drive..." -Verbose
$exeSource = Get-ChildItem -path "/$Executable" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
}
if(!$exeSource)
{
throw "$Executable not found"
}
$exePath = Split-Path -Path $exeSource
Add-Path -path $exePath
}
if($Cleanup.IsPresent)
{
Remove-Folder -Folder "$env:temp\chocolatey"
}
}
function Add-Path
{
param
(
$path
)
$machinePathString = [System.Environment]::GetEnvironmentVariable('path',[System.EnvironmentVariableTarget]::Machine)
$machinePath = $machinePathString -split ';'
if($machinePath -inotcontains $path)
{
$newPath = "$machinePathString;$path"
Write-Verbose "Adding $path to path..." -Verbose
[System.Environment]::SetEnvironmentVariable('path',$newPath,[System.EnvironmentVariableTarget]::Machine)
Write-Verbose "Added $path to path." -Verbose
$env:Path += ";$newPath"
}
else
{
Write-Verbose "$path already in path." -Verbose
}
}
function Remove-Folder
{
param(
[string]
$Folder
)
Write-Verbose "Cleaning up $Folder..." -Verbose
$filter = Join-Path -Path $Folder -ChildPath *
[int]$measuredCleanupMB = (Get-ChildItem $filter -Recurse | Measure-Object -Property Length -Sum).Sum / 1MB
Remove-Item -recurse -force $filter -ErrorAction SilentlyContinue
Write-Verbose "Cleaned up $measuredCleanupMB MB from $Folder" -Verbose
}