-
Notifications
You must be signed in to change notification settings - Fork 5
/
ps.ps1
52 lines (47 loc) · 1.82 KB
/
ps.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
param(
[Parameter(Mandatory=$true)]
[string]$script,
[Parameter(Mandatory=$false, ValueFromRemainingArguments=$true)]
[string[]]$scriptArguments
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
trap {
Write-Host "ERROR: $_"
($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1' | Write-Host
($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1' | Write-Host
Exit 1
}
# enable TLS 1.1 and 1.2.
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol `
-bor [Net.SecurityProtocolType]::Tls11 `
-bor [Net.SecurityProtocolType]::Tls12
# wrap the choco command (to make sure this script aborts when it fails).
function Start-Choco([string[]]$Arguments, [int[]]$SuccessExitCodes=@(0)) {
$command, $commandArguments = $Arguments
if ($command -eq 'install') {
$Arguments = @($command, '--no-progress') + $commandArguments
}
for ($n = 0; $n -lt 10; ++$n) {
if ($n) {
# NB sometimes choco fails with "The package was not found with the source(s) listed."
# but normally its just really a transient "network" error.
Write-Host "Retrying choco install..."
Start-Sleep -Seconds 3
}
&C:\ProgramData\chocolatey\bin\choco.exe @Arguments
if ($SuccessExitCodes -Contains $LASTEXITCODE) {
return
}
}
throw "$(@('choco')+$Arguments | ConvertTo-Json -Compress) failed with exit code $LASTEXITCODE"
}
function choco {
Start-Choco $Args
}
Set-Location c:\vagrant
$script = Resolve-Path $script
Set-Location (Split-Path -Parent $script)
Write-Host "Running $script..."
. ".\$(Split-Path -Leaf $script)" @scriptArguments