-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInstall-FromChoco.ps1
More file actions
98 lines (79 loc) · 2.88 KB
/
Install-FromChoco.ps1
File metadata and controls
98 lines (79 loc) · 2.88 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
# Copyright (c) 2025, the WebKit for Windows project authors. Please see the
# AUTHORS file for details. All rights reserved. Use of this source code is
# governed by a BSD-style license that can be found in the LICENSE file.
<#
.Synopsis
Installs a Windows package through choco.
.Description
Installs a package from chocolatey onto the system.
.Parameter Name
The name of the package.
.Parameter Version
The version of the package to install.
.Parameter Options
A list of options to pass in.
.Parameter InstallerOptions
A list of options to pass to the installer.
.Parameter PackageParameters
A list of parameters to pass to the package.
.Parameter NoVerify
If set the installation is not verified by attempting to call an executable
with the given name.
.Parameter VerifyExe
The executable to use to verify the installation. If not provided defaults to
the name.
.Parameter VersionOptions
The options to pass to the executable to get the version.
#>
function Install-FromChoco {
param(
[Parameter(Mandatory)]
[string]$name,
[Parameter()]
[string]$version,
[Parameter()]
[string[]]$options = @(),
[Parameter()]
[string[]]$installerOptions = @(),
[Parameter()]
[string[]]$packageParameters = @(),
[Parameter()]
[switch]$noVerify = $false,
[Parameter()]
[string]$verifyExe,
[Parameter()]
[string[]]$versionOptions = @('--version')
)
$chocoArgs = @('install',$name,'--confirm');
$chocoArgs += $options;
if ($version) {
$chocoArgs += @('--version',$version);
}
if ($installerOptions) {
$chocoArgs += @('--install-arguments',("'{0}'" -f ($installerOptions -join ' ')));
}
if ($packageParameters) {
$chocoArgs += @('--package-parameters',("'{0}'" -f ($packageParameters -join ' ')));
}
Write-Information ('choco {0}' -f ($chocoArgs -join ' '));
$process = Start-Process choco -Passthru -NoNewWindow -ArgumentList $chocoArgs;
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments','',Scope = 'Function')]
$handle = $process.Handle;
$process.WaitForExit();
if ($process.ExitCode -ne 0) {
Write-Error ('{0} installer failed with exit code {1}' -f $name,$process.ExitCode) -ErrorAction Stop;
return;
}
# Update path
Import-Module $env:ChocolateyInstall\helpers\chocolateyProfile.psm1;
refreshenv;
if (!$noVerify) {
if (!$verifyExe) {
$verifyExe = $name;
}
Write-Information -MessageData ('Verifying {0} install ...' -f $name) -InformationAction Continue;
$verifyCommand = (' {0} {1}' -f $verifyExe,($versionOptions -join ' '));
Write-Information -MessageData $verifyCommand -InformationAction Continue;
Invoke-Expression $verifyCommand;
}
}