-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps.ps1
84 lines (77 loc) · 2.34 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
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
param(
[Parameter(Mandatory=$true)]
[String]$script
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'
trap {
Write-Output "ERROR: $_"
Write-Output (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1')
Write-Output (($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1')
Exit 1
}
# use TLS 1.2.
[Net.ServicePointManager]::SecurityProtocol = [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
}
Add-Type @'
using System;
using System.Runtime.InteropServices;
public static class Windows
{
[DllImport("kernel32", SetLastError=true)]
public static extern UInt64 GetTickCount64();
public static TimeSpan GetUptime()
{
return TimeSpan.FromMilliseconds(GetTickCount64());
}
}
'@
function Wait-ForCondition {
param(
[scriptblock]$Condition,
[int]$DebounceSeconds=5
)
process {
$begin = [Windows]::GetUptime()
do {
Start-Sleep -Seconds 1
try {
$result = &$Condition
} catch {
$result = $false
}
if (-not $result) {
$begin = [Windows]::GetUptime()
continue
}
} while ((([Windows]::GetUptime()) - $begin).TotalSeconds -lt $DebounceSeconds)
}
}
cd c:/vagrant
$script = Resolve-Path $script
cd (Split-Path $script -Parent)
Write-Host "Running $script..."
. $script