-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathauxiliary.ps1
129 lines (107 loc) · 3.31 KB
/
auxiliary.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
$FILTERS = "https://go.microsoft.com/fwlink/?linkid=875139"
$STUDIOCOMPUTERNAME = "STUDIO"
$CLIENTCOMPUTERNAME = "CL"
$CONTROLNET = "192.168.100" # The =FIRST THREE= octets of the IP
$STUDIOIP = "${CONTROLNET}.1"
$KITTYPE = "HLK"
$HLKKITVER = 1809
$REMOVEGUI = $false
$DEBUG = $false
$STAGEFILE = "$env:TEMP\current-stage.txt"
$ARGSPATH = "$PSScriptRoot\args.ps1"
$EXTRASOFTWAREDIRECTORY = "$PSScriptRoot\extra-software"
if (Test-Path -Path "$ARGSPATH") {
. "$ARGSPATH"
}
function Execute-Command ($Path, $Arguments) {
Write-Output "Execution $Path $Arguments"
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "$Path"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.Arguments = "$Arguments"
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$OutEvent = Register-ObjectEvent -Action {
Write-Output $Event.SourceEventArgs.Data
} -InputObject $p -EventName "OutputDataReceived"
$ErrEvent = Register-ObjectEvent -Action {
Write-Output $Event.SourceEventArgs.Data
} -InputObject $p -EventName "ErrorDataReceived"
$p.Start()
$p.BeginOutputReadLine()
$p.BeginErrorReadLine()
# Do not think about calling WaitForExit on the process,
# because then no output is generated until the process
# has finished
do
{
Write-Output 'Waiting for process to finish...'
Start-Sleep -Seconds 1
}
while (!$p.HasExited)
if ($p.ExitCode -ne 0) {
Write-Error "Process exited with code $($p.ExitCode)"
} else {
Write-Output "Process exited successfully"
}
$OutEvent.Name, $ErrEvent.Name |
ForEach-Object {Unregister-Event -SourceIdentifier $_}
Write-Output "Execution finished"
}
function Set-NewStage() {
param (
$Stage
)
Write-Output "Set new stage to file: $Stage"
Set-Content -Path "$STAGEFILE" -Value "$Stage"
}
function Get-CurrentStage() {
if ((Test-Path $STAGEFILE)) {
Get-Content -Path "$STAGEFILE"
} else {
Write-Output "One"
}
}
function Remove-Stage() {
Write-Output "Remove stage file: $STAGEFILE"
Remove-Item -Path "$STAGEFILE"
}
function Start-Stage() {
$stage = Get-CurrentStage
$time = Get-Date -UFormat "%d-%m-%Y-%H-%M-%S"
Start-Transcript -Path "$env:TEMP\install-$stage-$time.log" -Force
Write-Output "[$time] Starting stage $stage..."
Invoke-Expression "Stage-$stage"
}
function Safe-Restart() {
Stop-Transcript
if ($DEBUG -eq $true) {
Read-Host 'Press any key to continue...'
}
Restart-Computer
}
function Safe-Shutdown() {
Stop-Transcript
if ($DEBUG -eq $true) {
Read-Host 'Press any key to continue...'
}
Stop-Computer
}
function Set-Registry {
param (
$Path,
$Name,
$Value,
$Type
)
if (Test-Path "$Path") {
New-ItemProperty -Path "$Path" -Name "$Name" -Value "$Value" `
-PropertyType "$Type" -Force
} else {
New-Item -Path "$Path" -Force
New-ItemProperty -Path "$Path" -Name "$Name" -Value "$Value" `
-PropertyType "$Type" -Force
}
}