Chocolatey Helper (#646)

* Add basic choco install wrapper

* Use Install-Choco on mingw

* move azure-cli install to defence

* Rename ChocoInstall to ChocoHelpers
This commit is contained in:
Luke Duddridge
2020-04-14 06:51:57 +01:00
committed by GitHub
parent 20515c4206
commit 44e904205f
6 changed files with 40 additions and 4 deletions

View File

@@ -0,0 +1,33 @@
function Install-Choco {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$install,
[int]$retries = 5
)
begin { }
process {
$condition = $false
$count = 0
do {
Write-Output "running: powershell choco install $install -y"
powershell choco install $install -y
$installed = powershell choco list -lo $install --all
$match = (($installed -match "^$install.*").Length -ne 0)
if ($match) {
Write-Output "package installed: $install"
$condition = $true
}
else {
$count++
if ($count -eq $retries) {
Write-Error "Could not install $install after $count attempts"
exit 1
}
}
} while ($condition -eq $false)
}
end { }
}

View File

@@ -4,6 +4,7 @@ param()
. $PSScriptRoot\PathHelpers.ps1 . $PSScriptRoot\PathHelpers.ps1
. $PSScriptRoot\InstallHelpers.ps1 . $PSScriptRoot\InstallHelpers.ps1
. $PSScriptRoot\MarkdownHelpers.ps1 . $PSScriptRoot\MarkdownHelpers.ps1
. $PSScriptRoot\ChocoHelpers.ps1
Export-ModuleMember -Function @( Export-ModuleMember -Function @(
'Test-MachinePath' 'Test-MachinePath'
@@ -26,4 +27,5 @@ Export-ModuleMember -Function @(
'Get-WinVersion' 'Get-WinVersion'
'Test-IsWin19' 'Test-IsWin19'
'Test-IsWin16' 'Test-IsWin16'
'Install-Choco'
) )

View File

@@ -3,7 +3,8 @@ function Install-MSI
Param Param
( (
[String]$MsiUrl, [String]$MsiUrl,
[String]$MsiName [String]$MsiName,
[int]$retries = 5
) )
$exitCode = -1 $exitCode = -1

View File

@@ -1,5 +1,5 @@
function Add-ContentToMarkdown { function Add-ContentToMarkdown {
[CmdletBinding()]
param( param(
$Content = "" $Content = ""
) )

View File

@@ -3,7 +3,7 @@
## Desc: Install Azure CLI ## Desc: Install Azure CLI
################################################################################ ################################################################################
choco install azure-cli -y Install-Choco "azure-cli"
$AzureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory' $AzureCliExtensionPath = Join-Path $Env:CommonProgramFiles 'AzureCliExtensionDirectory'
New-Item -ItemType "directory" -Path $AzureCliExtensionPath New-Item -ItemType "directory" -Path $AzureCliExtensionPath

View File

@@ -5,7 +5,7 @@
Import-Module -Name ImageHelpers -Force Import-Module -Name ImageHelpers -Force
choco install -y mingw Install-Choco "mingw"
# Make a copy of mingw32-make.exe to make.exe, which is a more discoverable name # Make a copy of mingw32-make.exe to make.exe, which is a more discoverable name
# and so the same command line can be used on Windows as on macOS and Linux # and so the same command line can be used on Windows as on macOS and Linux