-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwin-dev.ps1
344 lines (294 loc) · 14 KB
/
win-dev.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# Install base development tools
# . { iwr -useb https://raw.githubusercontent.com/cdaf/windows/master/win-dev.ps1 } | iex
# To perform custom steps
# iwr -useb https://raw.githubusercontent.com/cdaf/windows/master/win-dev.ps1 -o win-dev.ps1
# Install Virtualisation, include Vagrant client
# .\win-dev.ps1 hyperv or .\win-dev.ps1 hyperv <smbpassword> or .\win-dev.ps1 hyperv <smbpassword> <smbusername>
# .\win-dev.ps1 virtualbox
# Install Docker Desktop, requires Hyper-V, so steps above are performed
# .\win-dev.ps1 docker
# Legacy Software Components
# .\win-dev.ps1 legacy
Param (
[string]$virtualisation,
[string]$vagrantPass,
[string]$vagrantUser
)
cmd /c "exit 0"
$Error.Clear()
# Consolidated Error processing function
function ERRMSG ($message, $exitcode) {
if ( $exitcode ) {
Write-Host "`n[$scriptName]$message" -ForegroundColor Red
} else {
Write-Host "`n[$scriptName]$message" -ForegroundColor Yellow
}
if ( $error ) {
$i = 0
foreach ( $item in $Error )
{
Write-Host "`$Error[$i] $item"
$i++
}
$Error.clear()
}
if ( $env:CDAF_ERROR_DIAG ) {
Write-Host "`n[$scriptName] Invoke custom diag `$env:CDAF_ERROR_DIAG = $env:CDAF_ERROR_DIAG`n"
Invoke-Expression $env:CDAF_ERROR_DIAG
}
if ( $exitcode ) {
Write-Host "`n[$scriptName] Exit with LASTEXITCODE = $exitcode`n" -ForegroundColor Red
exit $exitcode
}
}
# Common expression logging and error handling function, copied, not referenced to ensure atomic process
function executeExpression ($expression) {
Write-Host "[$(Get-Date)] $expression"
try {
Invoke-Expression $expression
if(!$?) { ERRMSG "[TRAP] `$? = $?" 1211 }
} catch {
$message = $_.Exception.Message
$_.Exception | format-list -force
$_.Exception.StackTrace
if (( $LASTEXITCODE ) -and ( $LASTEXITCODE -ne 0 )) {
ERRMSG "[EXCEPTION] $message" $LASTEXITCODE
} else {
ERRMSG "[EXCEPTION] $message" 1212
}
}
if ( $LASTEXITCODE ) {
if ( $LASTEXITCODE -ne 0 ) {
if ( $LASTEXITCODE -eq 3010 ) {
ERRMSG "[WARN] Pending Reboot, `$LASTEXITCODE is $LASTEXITCODE"
} else {
ERRMSG "[EXIT] `$LASTEXITCODE is $LASTEXITCODE" $LASTEXITCODE
}
} else {
if ( $error ) {
ERRMSG "[WARN] `$LASTEXITCODE is $LASTEXITCODE, but standard error populated"
}
}
} else {
if ( $error ) {
if ( $env:CDAF_IGNORE_WARNING -eq 'no' ) {
ERRMSG "[ERROR] `$env:CDAF_IGNORE_WARNING is 'no' so exiting" 1213
} else {
ERRMSG "[WARN] `$LASTEXITCODE not set, but standard error populated"
}
}
}
}
function executeCMD ($expression, $ignore) {
$error.clear()
Write-Host "[$(Get-Date)] $expression"
try {
cmd /c $expression
if(!$?) { ERRMSG "[TRAP] `$? = $?" $(if ( ! $ignore ) { 1211 }) }
} catch {
$message = $_.Exception.Message
$_.Exception | format-list -force
$_.Exception.StackTrace
if (( $LASTEXITCODE ) -and ( $LASTEXITCODE -ne 0 )) {
ERRMSG "[EXEC][EXCEPTION] $message" $(if ( ! $ignore ) { $LASTEXITCODE })
} else {
ERRMSG "[EXEC][EXCEPTION] $message" $(if ( ! $ignore ) { 1212 })
}
}
if ( $LASTEXITCODE ) {
if ( $LASTEXITCODE -ne 0 ) {
ERRMSG "[EXEC][EXIT] `$LASTEXITCODE is $LASTEXITCODE" $(if ( ! $ignore ) { $LASTEXITCODE })
} else {
if ( $error ) {
ERRMSG "[EXEC][WARN] `$LASTEXITCODE is $LASTEXITCODE, but standard error populated"
}
}
} else {
if ( $error ) {
if ( $env:CDAF_IGNORE_WARNING -eq 'no' ) {
ERRMSG "[EXEC][ERROR] `$env:CDAF_IGNORE_WARNING is 'no' so exiting" $(if ( ! $ignore ) { 1213 })
} else {
ERRMSG "[EXEC][WARN] `$LASTEXITCODE not set, but standard error populated"
}
}
}
}
# Execute expression, log errors but ignore and proceed
function IGNORE ($expression) {
if ( $expression ) {
Write-Host "[$(Get-Date)] $expression"
try {
Invoke-Expression "$expression"
if(!$?) {
ERRMSG "[IGNORE][ERROR] `$? = $?"
}
} catch {
$_.Exception | format-list -force
$_.Exception.StackTrace
ERRMSG "[IGNORE][EXCEPTION] $_.Exception"
}
if ( $LASTEXITCODE ) {
if ( $LASTEXITCODE -ne 0 ) {
ERRMSG "[IGNORE][LASTEXITCODE] `$LASTEXITCODE = $LASTEXITCODE`n"
cmd /c "exit 0"
}
}
if ( $error ) {
ERRMSG "[IGNORE][WARN] `$Error[] = $Error"
}
}
}
function MD5MSK ($value) {
(Get-FileHash -InputStream $([IO.MemoryStream]::new([byte[]][char[]]$value)) -Algorithm MD5).Hash
}
$scriptName = 'win-dev.ps1'
Write-Host "`n[$scriptName] ---------- start ----------"
if ($virtualisation) {
Write-Host "virtualisation : $virtualisation"
} else {
Write-Host "virtualisation : (not specified, developer configuration)"
}
if ($vagrantPass) {
Write-Host "vagrantPass : $(MD5MSK $vagrantPass) (MD5 mask)"
} else {
Write-Host "vagrantPass : (not specified)"
}
if ($vagrantPass) {
Write-Host "vagrantUSer : $vagrantUser"
} else {
Write-Host "vagrantPass : (not specified, will use current user if password set)"
}
if ( $env:http_proxy ) {
executeExpression "[system.net.webrequest]::defaultwebproxy = New-Object system.net.webproxy('$env:http_proxy')"
} else {
executeExpression '(New-Object System.Net.WebClient).Proxy.Credentials =[System.Net.CredentialCache]::DefaultNetworkCredentials'
}
executeExpression "cd ~"
Write-Host "Allow script execution, do not fail if not allowed"
Write-Host "set-executionpolicy unrestricted -Force`n"
try { set-executionpolicy unrestricted -Force } catch { Write-Warning "Unable to alter powershell execution policy, continuing ..." }
$error.clear()
executeExpression ". { iwr -useb http://cdaf.io/static/app/downloads/cdaf.ps1 } | iex"
if (( $virtualisation -eq 'hyperv' ) -or ( $virtualisation -eq 'docker' )) {
executeExpression "Dism /online /enable-feature /all /featurename:Microsoft-Hyper-V /NoRestart"
# ensure console is activated
executeExpression "Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All"
executeExpression "Enable-WindowsOptionalFeature -Online -FeatureName Containers -All -NoRestart"
if ($vagrantPass) {
executeExpression ".\automation\provisioning\base.ps1 'vagrant' -autoReboot no"
executeExpression ".\automation\provisioning\setenv.ps1 VAGRANT_DEFAULT_PROVIDER hyperv"
executeExpression ".\automation\provisioning\setenv.ps1 VAGRANT_SMB_PASS $vagrantPass"
if ($vagrantUser) {
executeExpression ".\automation\provisioning\setenv.ps1 VAGRANT_SMB_USER $vagrantUser"
} else {
executeExpression ".\automation\provisioning\setenv.ps1 VAGRANT_SMB_USER $env:USERNAME"
}
}
if ( $virtualisation -eq 'docker' ) {
executeExpression ".\automation\provisioning\base.ps1 docker-desktop"
}
$restart = 'yes'
} elseif ( $virtualisation -eq 'virtualbox' ) {
executeExpression "addHOSTS.ps1 172.16.17.90 cbe.mshome.net"
executeExpression "addHOSTS.ps1 172.16.17.98 dc.mshome.net"
executeExpression "addHOSTS.ps1 172.16.17.99 db.mshome.net"
executeExpression "addHOSTS.ps1 172.16.17.100 agent.mshome.net"
executeExpression "addHOSTS.ps1 172.16.17.100 build.mshome.net"
executeExpression "addHOSTS.ps1 172.16.17.101 server-1.mshome.net"
executeExpression "addHOSTS.ps1 172.16.17.102 server-2.mshome.net"
executeExpression "addHOSTS.ps1 172.16.17.101 windows-1.mshome.net"
executeExpression "addHOSTS.ps1 172.16.17.102 windows-2.mshome.net"
executeExpression "addHOSTS.ps1 172.16.17.103 app.mshome.net"
executeExpression ".\automation\provisioning\base.ps1 'virtualbox'"
$restart = 'yes'
} elseif ( $virtualisation -eq 'legacy' ) {
executeExpression ".\automation\provisioning\base.ps1 svn"
executeExpression ".\automation\provisioning\base.ps1 vnc-viewer"
executeExpression ".\automation\provisioning\base.ps1 dotnet3.5"
executeExpression ".\automation\provisioning\base.ps1 vagrant"
$restart = 'yes'
} else {
executeExpression "Set-Service beep -StartupType disabled"
executeExpression "Get-AppxPackage Microsoft.YourPhone -AllUsers | Remove-AppxPackage"
executeExpression "(Get-WmiObject Win32_TerminalServiceSetting -Namespace root\cimv2\TerminalServices).SetAllowTsConnections(1,1) | Out-Null"
executeExpression "(Get-WmiObject -Class 'Win32_TSGeneralSetting' -Namespace root\cimv2\TerminalServices -Filter `"TerminalName='RDP-tcp'`").SetUserAuthenticationRequired(0) | Out-Null"
executeExpression "Get-NetFirewallRule -DisplayName `"Remote Desktop*`" | Set-NetFirewallRule -enabled true"
executeExpression ".\automation\provisioning\base.ps1 'microsoft-openjdk11 maven eclipse'"
executeExpression ".\automation\provisioning\base.ps1 nodejs-lts"
executeExpression ".\automation\provisioning\base.ps1 python"
executeExpression ".\automation\provisioning\base.ps1 'nuget.commandline'" # was fixed to -verion 5.8.1 as 5.9 was broken
# Install explicitely to include Agent, VS workload will not include agent & choco does not support Web Deploy v4
executeExpression ".\automation\provisioning\webdeploy.ps1"
executeExpression ".\automation\provisioning\base.ps1 visualstudio2022professional"
executeExpression "curl.exe -fSL $env:CURL_OPT -O https://aka.ms/vs/17/release/vs_professional.exe"
executeCMD "start /w vs_professional.exe --quiet --wait --norestart --nocache --noUpdateInstaller --noWeb --add Microsoft.VisualStudio.Workload.Azure --locale en-US"
executeCMD "start /w vs_professional.exe --quiet --wait --norestart --nocache --noUpdateInstaller --noWeb --add Microsoft.VisualStudio.Workload.NetWeb --locale en-US"
executeCMD "start /w vs_professional.exe --quiet --wait --norestart --nocache --noUpdateInstaller --noWeb --add Microsoft.VisualStudio.Workload.WebBuildTools --locale en-US"
executeCMD "start /w vs_professional.exe --quiet --wait --norestart --nocache --noUpdateInstaller --noWeb --add Microsoft.VisualStudio.Workload.ManagedDesktop --locale en-US"
executeCMD "start /w vs_professional.exe --quiet --wait --norestart --nocache --noUpdateInstaller --noWeb --add Microsoft.VisualStudio.Workload.Node --locale en-US"
executeCMD "start /w vs_professional.exe --quiet --wait --norestart --nocache --noUpdateInstaller --noWeb --add Microsoft.VisualStudio.Workload.Python --locale en-US"
executeCMD "start /w vs_professional.exe --quiet --wait --norestart --nocache --noUpdateInstaller --noWeb --add Microsoft.Component.PythonTools.Web --locale en-US"
Write-Host "Install Latest .NET SDKs"
executeExpression ".\automation\provisioning\base.ps1 netfx-4.8-devpack" # 4.8
executeExpression ".\automation\provisioning\base.ps1 dotnet-sdk"
executeExpression ".\automation\provisioning\base.ps1 azure-cli"
executeExpression "az config set extension.use_dynamic_install=yes_without_prompt"
# Ensure NuGet is a source, by default it is not (ignore if already added)
Write-Host "nuget sources add -Name NuGet.org -Source https://api.nuget.org/v3/index.json"
nuget sources add -Name NuGet.org -Source https://api.nuget.org/v3/index.json
executeExpression ".\automation\provisioning\base.ps1 'vswhere'" # Install this now that VS is installed
executeExpression ".\automation\provisioning\base.ps1 nano"
executeExpression ".\automation\provisioning\base.ps1 putty"
executeExpression ".\automation\provisioning\base.ps1 winscp"
executeExpression ".\automation\provisioning\base.ps1 postman"
executeExpression ".\automation\provisioning\base.ps1 terraform"
executeExpression ".\automation\provisioning\base.ps1 git"
executeExpression "git config --global core.autocrlf false"
executeExpression ".\automation\provisioning\base.ps1 vscode"
$extensions = @()
$extensions += "42crunch.vscode-openapi"
$extensions += "bierner.markdown-mermaid"
$extensions += "bmewburn.vscode-intelephense-client"
$extensions += "cweijan.vscode-mysql-client2"
$extensions += "DotJoshJohnson.xml"
$extensions += "hashicorp.terraform"
$extensions += "hediet.vscode-drawio"
$extensions += "jmrog.vscode-nuget-package-manager"
$extensions += "marcostazi.VS-code-vagrantfile"
$extensions += "ms-dotnettools.csharp"
$extensions += "ms-azuretools.vscode-azurefunctions"
$extensions += "ms-azuretools.vscode-azureresourcegroups"
$extensions += "ms-azuretools.vscode-cosmosdb"
$extensions += "ms-azuretools.vscode-docker"
$extensions += "ms-python.python"
$extensions += "ms-python.vscode-pylance"
$extensions += "ms-toolsai.jupyter"
$extensions += "ms-toolsai.vscode-ai"
$extensions += "ms-toolsai.vscode-ai-remote"
$extensions += "ms-vscode.azure-account"
$extensions += "ms-vscode.powershell"
$extensions += "ms-vscode-remote.remote-containers"
$extensions += "ms-vscode-remote.remote-ssh"
$extensions += "ms-vscode-remote.remote-wsl"
$extensions += "msazurermtools.azurerm-vscode-tools"
$extensions += "pronto-4gl-vscode-lang.pronto-4gl-language-definition"
$extensions += "puppet.puppet-vscode"
$extensions += "redhat.vscode-yaml"
$extensions += "streetsidesoftware.code-spell-checker"
$extensions += "vscoss.vscode-ansible"
foreach ($extension in $extensions) {
IGNORE "code --install-extension $extension --force"
}
Write-Host "Google does not provide a static download for Chrome, so checksum can briefly fail on new releases, if install fails, this script will not error."
Write-Host ".\automation\provisioning\base.ps1 'googlechrome' -checksum ignore"
.\automation\provisioning\base.ps1 'googlechrome' -checksum ignore
}
Write-Host "`n[$scriptName] List installed Chocolatey packages..."
executeExpression "choco list --localonly --limit-output"
Write-Host "`n[$scriptName] Clean-up"
executeExpression "Remove-Item -Recurse -Force automation"
if ( $restart ) {
Write-Host "`n[$scriptName] Restart = $restart"
executeExpression "shutdown /r /t 0"
}
Write-Host "`n[$scriptName] ---------- stop ----------"