-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlServer-Version-Management.ps1
More file actions
4157 lines (3694 loc) · 190 KB
/
SqlServer-Version-Management.ps1
File metadata and controls
4157 lines (3694 loc) · 190 KB
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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Include Directive: [ src\Includes\Synopsis.ps1 ]
# Include File: [\SqlSetup.PS1Project\src\Includes\Synopsis.ps1]
<#
.Synopsis
SQL Server Setup and Management including Developer, Express, and LocalDB editions.
The intended use of this project is for Continuous Integration (CI) scenarios, where:
• SQL Server or LocalDB needs to be installed without user interaction.
• SQL Server or LocalDB installation doesn’t need to persist across multiple CI runs.
SQL Server Setup defaults:
• Features are SQL Engine and full text search,
• Built-in Administrators (or localized name) are SQL Server Administrators for SSPI,
• TCP/IP and Named Pipe protocols are on,
• sa password is ‘Meaga$tr0ng’.
The guide: https://devizer.github.io/SqlServer-Version-Management
.Description
- Supports Windows 7 ... Windows 11, and Windows Server 2008 R2+ ... Windows Server 2025. Windows on ARM64 is also supported.
.Example
$errors = Setup-SqlServers -SqlServers "2025 Developer: MSSQLSERVER"
.Example
$errors = Setup-SqlServers -SqlServers "2025 Developer: DEVELOPER2025, 2019 Developer: DEVELOPER2019"
.Example
# Next example installs 32 or 64 bit Sql Server 2014 depending on Windows Architecture
$errors = Setup-SqlServers -SqlServers "2014 Developer: DEVELOPER2014"
.Example
# Next example installs 32 or 64 bit Sql Server 2016 Express depending on Windows Architecture
$errors = Setup-SqlServers -SqlServers "2016 Core: SQLEXPRESS"
#>
# Include Directive: [ src\Includes\Import-DevOps.ps1 ]
# Include File: [\SqlSetup.PS1Project\src\Includes\Import-DevOps.ps1]
# This implicit call resolves conflict with bash shell scripts names
function Import-DevOps() {
$ModuleName = "SqlServer-Version-Management"
$exception=$null;
$wp=$WarningPreference;
$WarningPreference="SilentlyContinue"
# Actual Powershell Version
try { Import-Module "$ModuleName" 3>$null; $okActual = $true; } catch { $exception = $_.Exception; }
if (-not $okActual) {
# Legacy Powershell Version
try { Import-Module "$ModuleName" ; $okLegacy = $true; } catch { $exception = $_.Exception; Write-Host "Warning! Import-Module $ModuleName failed$([Environment]::NewLine)$($_.Exception)" -ForegroundColor DarkRed }
}
if ($okActual -or $okLegacy) {
# Write-Host "Module '$ModuleTitle' Successfully imported" -ForeGroundColor Green
}
$WarningPreference=$wp;
}
# Import-DevOps; Try-And-Retry "curl should fail" { & "curl.exe" -I https://google.com2 }
# Include Directive: [ ..\Includes\*.ps1 ]
# Include File: [\Includes\$Full7zLinksMetadata.ps1]
$Full7zLinksMetadata_onWindows = @(
@{ Ver = 2301;
X64Links = @(
"https://www.7-zip.org/a/7z2301-x64.exe",
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-x64-2301.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-x64-2301.7z?viasf=1"
);
ARM64Links = @(
"https://www.7-zip.org/a/7z2301-arm64.exe",
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-arm64-2301.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-arm64-2301.7z?viasf=1"
);
X86Links = @(
"https://www.7-zip.org/a/7z2301.exe",
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-x86-2301.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-x86-2301.7z?viasf=1"
)
},
@{ Ver = 2201;
X64Links = @(
"https://www.7-zip.org/a/7z2201-x64.exe",
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-x64-2201.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-x64-2201.7z?viasf=1"
);
ARM64Links = @(
"https://www.7-zip.org/a/7z2201-arm64.exe",
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-arm64-2201.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-arm64-2201.7z?viasf=1"
);
X86Links = @(
"https://www.7-zip.org/a/7z2201.exe",
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-x86-2201.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-x86-2201.7z?viasf=1"
)
},
@{ Ver = 1900;
X64Links = @(
"https://www.7-zip.org/a/7z1900-x64.exe",
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-x64-1900.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-x64-1900.7z?viasf=1"
);
X86Links = @(
"https://www.7-zip.org/a/7z1900.exe",
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-x86-1900.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-x86-1900.7z?viasf=1"
)
},
@{ Ver = 1604;
X64Links = @(
"https://www.7-zip.org/a/7z1604-x64.exe",
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-x64-1604.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-x64-1604.7z?viasf=1"
);
X86Links = @(
"https://www.7-zip.org/a/7z1604.exe",
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-x86-1604.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-x86-1604.7z?viasf=1"
)
},
@{ Ver = 920;
X86Links = @(
"https://sourceforge.net/projects/p7zz-repack/files/windows/7z-full-x86-920.7z/download",
"https://master.dl.sourceforge.net/project/p7zz-repack/windows/7z-full-x86-920.7z?viasf=1"
)
}
);
<#
https://www.7-zip.org/a/7z2301-arm64.exe
https://www.7-zip.org/a/7z2301-x64.exe
https://www.7-zip.org/a/7z2301.exe
https://www.7-zip.org/a/7z2201-arm64.exe
https://www.7-zip.org/a/7z2201-x64.exe
https://www.7-zip.org/a/7z2201.exe
https://www.7-zip.org/a/7z1900-x64.exe
https://www.7-zip.org/a/7z1900.exe
https://www.7-zip.org/a/7z1604-x64.exe
https://www.7-zip.org/a/7z1604.exe
https://www.7-zip.org/a/7z920.exe
https://www.7-zip.org/a/7z920-arm.exe
https://www.7-zip.org/a/7zr.exe
#>
# Include File: [\Includes\$VcRuntimeLinksMetadata.ps1]
$VcRuntimeLinksMetadata = @(
@{ Ver=14;
Args="/install /passive /norestart";
X64Link="https://aka.ms/vs/17/release/vc_redist.x64.exe";
X86Link="https://aka.ms/vs/17/release/vc_redist.x86.exe";
ARM64Link="https://aka.ms/vs/17/release/vc_redist.arm64.exe"
},
@{ Ver=12;
Args="/install /passive /norestart";
X64Link="https://aka.ms/highdpimfc2013x64enu";
X86Link="https://aka.ms/highdpimfc2013x86enu";
},
@{ Ver=11;
Args="/install /passive /norestart";
X64Link="https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x64.exe";
X86Link="https://download.microsoft.com/download/1/6/B/16B06F60-3B20-4FF2-B699-5E9B7962F9AE/VSU_4/vcredist_x86.exe";
},
@{ Ver=10;
Args="/q /norestart";
X64Link="https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x64.exe";
X86Link="https://download.microsoft.com/download/1/6/5/165255E7-1014-4D0A-B094-B6A430A6BFFC/vcredist_x86.exe";
},
@{ Ver=9;
Args="/q /norestart";
X64Link="https://download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x64.exe";
X86Link="https://download.microsoft.com/download/5/D/8/5D8C65CB-C849-4025-8E95-C3966CAFD8AE/vcredist_x86.exe";
},
@{ Ver=8;
Args="/q:a";
# FULLY SILENT X64 on x86: /q /c:"msiexec /i vcredist.msi IACCEPTSQLLOCALDBLICENSETERMS=YES /qn /L*v c:\vc8b-x64.log"
X64Link="https://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x64.EXE";
X86Link="https://download.microsoft.com/download/8/B/4/8B42259F-5D70-43F4-AC2E-4B208FD8D66A/vcredist_x86.EXE";
}
);
# Include File: [\Includes\Add-Folder-To-Path.ps1]
function Add-Folder-To-Path([string] $folder, [string] $target = "User", [switch] $includeProcess = $true ) {
$thePath = [Environment]::GetEnvironmentVariable("PATH", "$target");
$arr = $thePath.Split(";")
$has = $null -ne ($arr | ? { $_ -eq $folder })
if ($has) {
Write-Host "Folder $folder already in the $($target) path"
}
else {
$arr += "$folder"
$newPath = $arr -join ";"
Write-Host "New $($target) Path: '$newPath'"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "$target");
}
if (($includeProcess -eq $true) -and ($target -ne "Process")) { Add-Folder-To-Path $folder "Process" $false }
}
function Add-Folder-To-System-Path([string] $folder) {
Add-Folder-To-Path "$folder" "Machine"
}
function Add-Folder-To-User-Path([string] $folder) {
Add-Folder-To-Path "$folder" "User"
}
# Add-Folder-To-User-Path "C:\TEST-TEST-TEST" -IncludeProcess:$false
# Include File: [\Includes\Append-All-Text.ps1]
function Append-All-Text( [string]$file, [string]$text ) {
Create-Directory-for-File $file
$utf8=new-object System.Text.UTF8Encoding($false);
[System.IO.File]::AppendAllText($file, $text, $utf8);
}
function Write-All-Text( [string]$file, [string]$text ) {
Create-Directory-for-File $file
$utf8=new-object System.Text.UTF8Encoding($false);
[System.IO.File]::WriteAllText($file, $text, $utf8);
}
# Include File: [\Includes\Bootstrap-Aria2-If-Required.ps1]
# on windows 7 api.gitgub.com, etc are not available
function Bootstrap-Aria2-If-Required(
[bool] $force = $false,
[string] $deployMode = "copy-to", # copy-to | modify-path
[string] $copyToFolder = $ENV:SystemRoot
)
{
if ((Get-Os-Platform) -ne "Windows") { return; }
$major = [System.Environment]::OSVersion.Version.Major;
$minor = [System.Environment]::OSVersion.Version.Minor;
$canWebClient = ($major -gt 6) -or ($major -eq 6 -and $minor -ge 2);
$okAria=$false; try { & aria2c.exe -h *| out-null; $okAria=$? } catch {}
if (-not $force) {
if ($canWebClient -or $okAria) { return; }
}
$ariaExe = Get-Aria2c-Exe-FullPath-for-Windows
if ($deployMode -eq "copy-to") {
Copy-Item $ariaExe $copyToFolder -Force -EA Continue
Write-Host "Provisioning aria2.exe for Windows $major.$minor. Copied to $copyToFolder"
} elseif ($deployMode -eq "modify-path") {
$dir=[System.IO.Path]::GetDirectoryName($ariaExe)
$ENV:PATH="$($ENV:PATH);$($dir)"
Write-Host "Provisioning aria2.exe for Windows $major.$minor. Added $dir to PATH"
}
}
# Include File: [\Includes\Combine-Path.ps1]
function Combine-Path($start) { foreach($a in $args) { $start=[System.IO.Path]::Combine($start, $a); }; $start }
# Include File: [\Includes\Create-Directory.ps1]
function Create-Directory($dirName) {
if ($dirName) {
$err = $null;
try {
$_ = [System.IO.Directory]::CreateDirectory($dirName); return;
} catch {
$err = "Create-Directory failed for `"$dirName`". $($_.Exception.GetType().ToString()) $($_.Exception.Message)"
Write-Host "Warning! $err";
throw $err;
}
}
}
function Create-Directory-for-File($fileFullName) {
$dirName=[System.IO.Path]::GetDirectoryName($fileFullName)
Create-Directory "$dirName";
}
# Include File: [\Includes\Demo-Test-of-Is-Vc-Runtime-Installed.ps1]
function Demo-Test-of-Is-Vc-Runtime-Installed() {
foreach($arch in @("X86", "X64", "ARM64")) {
Write-Host -NoNewline "$("{0,5}" -f $arch)| "
foreach($ver in $VcRuntimeLinksMetadata | % {$_.Ver}) {
$isInstalled = Is-Vc-Runtime-Installed $ver $arch
$color="Red"; if ($isInstalled) { $color="Green"; }
Write-Host -NoNewline "v$($ver)=$("{0,-8}" -f $isInstalled) " -ForegroundColor $color
}
Write-Host ""
}
}
# Include File: [\Includes\Demo-Test-of-Platform-Info.ps1]
function Demo-Test-of-Platform-Info() {
echo "Memory $((Get-Memory-Info).Description)"
echo "OS Platform: '$(Get-Os-Platform)'"
if ("$(Get-Os-Platform)" -ne "Windows") { echo "UName System: '$(Get-Nix-Uname-Value "-s")'" }
echo "CPU: '$(Get-Cpu-Name)'"
Measure-Action "The Greeting Test Action" {echo "Hello World"}
Measure-Action "The Fail Test Action" {$x=0; echo "Cant devide by zero $(42/$x)"; }
Measure-Action "The CPU Name" {echo "CPU: '$(Get-Cpu-Name)'"}
}; # test
# Include File: [\Includes\Download-And-Install-Specific-VC-Runtime.ps1]
function Download-And-Install-Specific-VC-Runtime([string] $arch, [int] $version, [bool] $wait = $true) {
$fullPath = Download-Specific-VC-Runtime $arch $version
$commandLine=$VcRuntimeLinksMetadata | where { "$($_.Ver)" -eq "$version" } | % { $_.Args }
# & "$fullPath" $commandLine.Split([char]32)
# $isOk = $?;
# return $isOk;
$isOk = $false
try {
Start-Process -FilePath "$fullPath" -ArgumentList ($commandLine.Split([char]32)) -Wait:$wait -NoNewWindow
$isOk = $true
} catch {}
return $isOk
}
# Include File: [\Includes\Download-File-FailFree-and-Cached.ps1]
function Download-File-FailFree-and-Cached([string] $fullName, [string[]] $urlList, [string] $algorithm="SHA512", [bool] $showFileSize = $false) {
if ((Is-File-Not-Empty "$fullName") -and (Is-File-Not-Empty "$fullName.$algorithm")) {
$hashActual = Get-Smarty-FileHash "$fullName" $algorithm
$hashExpected = Get-Content -Path "$fullName.$algorithm"
if ($hashActual -eq $hashExpected -and "$hashActual" -ne "") {
Troubleshoot-Info "File already downloaded: '" -Highlight "$fullName" "'"
return $true;
}
}
$isOk = [bool] ((Download-File-FailFree $fullName $urlList -ShowFileSize $showFileSize) | Select -Last 1)
if ($isOk) {
$hashActual = Get-Smarty-FileHash "$fullName" $algorithm
echo "$hashActual" > "$($fullName).$algorithm"
return $true;
}
return $false;
}
# Include File: [\Includes\Download-File-Managed.ps1]
function Download-File-Managed([string] $url, [string]$outfile, [bool] $showFileSize = $false) {
$dirName=[System.IO.Path]::GetDirectoryName($outfile)
Create-Directory "$dirName";
$okAria=$false; try { & aria2c.exe -h *| out-null; $okAria=$? } catch {}
if ($showFileSize) {
$urlFileLength = Query-Download-File-Size $url 6000
if ($urlFileLength) {
Write-Host "Download size is '$("{0:n0}" -f $urlFileLength)' bytes for url '$url'"
}
}
if ($okAria) {
Troubleshoot-Info "Starting download `"" -Highlight "$url" "`" using aria2c as `"" -Highlight "$outfile" "`""
# "-k", "2M",
$startAt = [System.Diagnostics.Stopwatch]::StartNew()
& aria2c.exe @("--allow-overwrite=true", "--check-certificate=false", "-x", "16", "-j", "16", "-d", "$($dirName)", "-o", "$([System.IO.Path]::GetFileName($outfile))", "$url") | out-null;
if ($?) {
<# Write-Host "aria2 rocks ($([System.IO.Path]::GetFileName($outfile)))"; #>
try { $length = (new-object System.IO.FileInfo($outfile)).Length; } catch {}; $milliSeconds = $startAt.ElapsedMilliseconds;
$size=""; if ($length -gt 0) { $size=" ($($length.ToString("n0")) bytes)"; }
$speed=""; if ($length -gt 0 -and $milliSeconds -gt 0) { $speed=" Speed is $(($length*1000/1024/$milliSeconds).ToString("n0")) Kb/s."; }
$duration=""; if ($milliSeconds -gt 0) {$duration=" It took $(($milliSeconds/1000.).ToString("n1")) seconds."; }
$downloadReport="Download of '$outfile'$($size) completed.$($duration)$($speed)";
Write-Host $downloadReport;
if ("$($ENV:SYSTEM_ARTIFACTSDIRECTORY)") { Append-All-Text (Combine-Path "$($ENV:SYSTEM_ARTIFACTSDIRECTORY)" "Download Speed Report.log") "$downloadReport$([Environment]::NewLine)"; }
return $true;
}
}
elseif (([System.Environment]::OSVersion.Version.Major) -eq 5 -and (Get-Os-Platform) -eq "Windows" ) {
Write-Host "Warning! Windows XP and Server 2003 requires aria2c.exe in the PATH for downloading." -ForegroundColor Red;
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
if ($PSVersionTable.PSEdition -ne "Core") {
[System.Net.ServicePointManager]::ServerCertificateValidationCallback={$true};
}
for ($i=1; $i -le 3; $i++) {
Troubleshoot-Info "Starting download attempt #$i `"" -Highlight "$url" "`" using built-in http client as `"" -Highlight "$outfile" "`""
$d=new-object System.Net.WebClient;
# $d.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36");
try {
$startAt = [System.Diagnostics.Stopwatch]::StartNew()
$d.DownloadFile("$url","$outfile");
try { $length = (new-object System.IO.FileInfo($outfile)).Length; } catch {}; $milliSeconds = $startAt.ElapsedMilliseconds;
$size=""; if ($length -gt 0) { $size=" ($($length.ToString("n0")) bytes)"; }
$speed=""; if ($length -gt 0 -and $milliSeconds -gt 0) { $speed=" Speed is $(($length*1000/1024/$milliSeconds).ToString("n0")) Kb/s."; }
$duration=""; if ($milliSeconds -gt 0) {$duration=" It took $(($milliSeconds/1000.).ToString("n1")) seconds."; }
$downloadReport="Download of '$outfile'$($size) completed.$($duration)$($speed)";
Write-Host $downloadReport;
if ("$($ENV:SYSTEM_ARTIFACTSDIRECTORY)") { Append-All-Text (Combine-Path "$($ENV:SYSTEM_ARTIFACTSDIRECTORY)" "Download Speed Report.log") "$downloadReport$([Environment]::NewLine)"; }
return $true
}
catch {
$fileExists = (Test-Path $outfile)
if ($fileExists) { Remove-Item $outfile -force }
# Write-Host $_.Exception -ForegroundColor DarkRed;
if ($i -lt 3) {
Write-Host "The download of the '$url' url failed.$([System.Environment]::NewLine)Retrying, $($i+1) of 3. $($_.Exception.Message)" -ForegroundColor Red;
sleep 1;
} else {
Write-Host "Unable to download of the '$url' url.$([System.Environment]::NewLine)$($_.Exception.Message)" -ForegroundColor Red;
}
}
}
return $false
}
function Download-File-FailFree([string] $outFile, [string[]] $urlList, [bool] $showFileSize = $false) {
foreach($url in $urlList) {
$isOk = Download-File-Managed $url $outFile -showFileSize $showFileSize | Select -Last 1;
if ($isOk) { return $true; }
}
return $fasle;
}
# Include File: [\Includes\Download-Specific-VC-Runtime.ps1]
function Download-Specific-VC-Runtime([string] $arch, [int] $version) {
$algorithm="SHA512"
$downloadFolder = Combine-Path "$(Get-PS1-Repo-Downloads-Folder)" "VC-Runtime"
$link = $VcRuntimeLinksMetadata | where {"$($_.Ver)" -eq "$version"} | % { $_."$($arch)Link"}
if (-not "$link") {
Write-Host "Warning! Undefined link for Visual C++ Runtime v$($version) for $arch architecture" -ForegroundColor Red
} else {
$fullPath = Combine-Path $downloadFolder "$arch-v$version" "$([System.IO.Path]::GetFilename($link))"
if (-not ($fullPath.ToLower().EndsWith(".exe"))) { $fullPath = "$($fullPath).exe"; }
if ((Is-File-Not-Empty "$fullPath") -and (Is-File-Not-Empty "$fullPath.$algorithm")) {
$hashActual = Get-Smarty-FileHash "$fullPath" $algorithm
$hashExpected = Get-Content -Path "$fullPath.$algorithm"
if ($hashActual -eq $hashExpected -and "$hashActual" -ne "") {
Troubleshoot-Info "Already downloaded " -Highlight "$arch" - "v" -Highlight "$($version)" ": '$fullPath'"
return $fullPath;
}
}
$isOk = [bool] (Download-File-Managed $link $fullPath)
if ($isOk) {
$hashActual = Get-Smarty-FileHash "$fullPath" $algorithm
echo "$hashActual" > "$($fullPath).$algorithm"
return $fullPath;
}
}
return "";
}
# Include File: [\Includes\Execute-Process-Smarty.ps1]
function Execute-Process-Smarty {
Param(
[string] $title,
[string] $launcher,
[string[]] $arguments,
[string] $workingDirectory = $null,
[int] $waitTimeout = 3600,
[switch] $Hidden = [switch] $false
)
$arguments = @($arguments | ? { "$_".Trim() -ne "" })
Troubleshoot-Info "[$title] `"$launcher`" $arguments";
$startAt = [System.Diagnostics.Stopwatch]::StartNew()
$ret = @{};
$windowStyle = if ($Hidden) { "Hidden" } else { "Normal" };
try {
if ($workingDirectory) {
$app = Start-Process "$launcher" -ArgumentList $arguments -WorkingDirectory $workingDirectory -PassThru -WindowStyle $windowStyle;
} else {
$app = Start-Process "$launcher" -ArgumentList $arguments -PassThru -WindowStyle $windowStyle;
}
} catch {
$err = "$($_.Exception.GetType()): '$($_.Exception.Message)'";
$ret = @{Error = "$title failed. $err"; };
}
$exitCode = $null;
$okExitCode = $false;
if (-not $ret.Error) {
if ($app -and $app.Id) {
$isExited = $app.WaitForExit(1000*$waitTimeout);
if (-not $isExited) {
$ret = @{ Error = "$title timed out." };
}
if (-not $ret.Error) {
sleep 0.01 # background tasks
$exitCode = [int] $app.ExitCode;
$isLegacy = ([System.Environment]::OSVersion.Version.Major) -eq 5;
if ($isExited -and $isLegacy -and "$exitCode" -eq "") { $exitCode = 0; }
$okExitCode = $exitCode -eq 0;
# Write-Host "Exit Code = [$exitCode], okExitCode = [$okExitCode]"
$ret = @{ExitCode = $exitCode};
if (-not $okExitCode) {
$err = "$title failed."; if ($app.ExitCode) { $err += " Exit code $($app.ExitCode)."; }
$ret = @{ Error = $err };
}
}
} else {
if (-not "$($ret.Error)") { $ret["Error"] = "$title failed."; }
}
}
$isOk = ((-not $ret.Error) -and $okExitCode);
$status = IIF $isOk "Successfully completed" $ret.Error;
if ($isOk) {
Write-Host "$title $status. It took $($startAt.ElapsedMilliseconds.ToString("n0")) ms";
} else {
Write-Host "$title $status. It took $($startAt.ElapsedMilliseconds.ToString("n0")) ms" -ForegroundColor DarkRed;
}
if (!$isOk -and ($app.Id)) {
# TODO: Windows Only
& taskkill.exe @("/t", "/f", "/pid", "$($app.Id)") | out-null;
}
return $ret;
}
# Include File: [\Includes\Extract-Archive-by-Default-Full-7z.ps1]
function Extract-Archive-by-Default-Full-7z([string] $fromArchive, [string] $toDirectory, $extractCommand = "x") {
New-Item -Path "$($toDirectory)" -ItemType Directory -Force -EA SilentlyContinue | Out-Null
$full7zExe = "$(Get-Full7z-Exe-FullPath-for-Windows)"
try { $fileOnly = [System.IO.Path]::GetFileName($fromArchive); } catch { $fileOnly = $fromArchive; }
$execResult = Execute-Process-Smarty "'$fileOnly' Extractor" $full7zExe @($extractCommand, "-y", "-o`"$toDirectory`"", "`"$fromArchive`"") -Hidden;
$ret = $true;
if ($execResult -and $execResult.Error) { $ret = $fasle; }
return $ret;
}
# Include File: [\Includes\Format-Table-Smarty.ps1]
function Format-Table-Smarty
{
$arr = (@($Input) | % { [PSCustomObject]$_} | Format-Table -AutoSize | Out-String -Width 2048).Split(@([char]13, [char]10)) | ? { "$_".Length -gt 0 };
if (-not $arr) { return; }
[string]::Join([Environment]::NewLine, $arr);
}
# Include File: [\Includes\Get-7z-Exe-FullPath-for-Windows.ps1]
function Get-Mini7z-Exe-FullPath-for-Windows() {
$algorithm="SHA512"
$ret = Combine-Path "$(Get-PS1-Repo-Downloads-Folder)" "7z-mini-x86" "7zr.exe";
$isOk = Download-File-FailFree-and-Cached $ret @("https://www.7-zip.org/a/7zr.exe", "https://sourceforge.net/projects/p7zz-repack/files/windows/7zr.exe/download")
return (IIF $isOk $ret $null);
}
function Get-Mini7z-Exe-FullPath-for-Windows-Prev() {
$algorithm="SHA512"
$ret = Combine-Path "$(Get-PS1-Repo-Downloads-Folder)" "7z-mini-x86" "7zr.exe";
if ((Is-File-Not-Empty "$ret") -and (Is-File-Not-Empty "$ret.$algorithm")) {
$hashActual = Get-Smarty-FileHash "$ret" $algorithm
$hashExpected = Get-Content -Path "$ret.$algorithm"
if ($hashActual -eq $hashExpected -and "$hashActual" -ne "") {
return $ret
}
} else {
$isOk = Download-File-Managed "https://www.7-zip.org/a/7zr.exe" $ret
if ($isOk) {
$hashActual = Get-Smarty-FileHash "$ret" $algorithm
echo "$hashActual" > "$($ret).$algorithm"
return $ret;
}
}
return $null
}
# Include File: [\Includes\Get-Aria2c-Exe-FullPath-for-Windows.ps1]
# arch: x86|x64|arm64|Xp
function Get-Aria2c-Exe-FullPath-for-Windows([string] $arch) {
$linkXp="https://github.com/q3aql/aria2-static-builds/releases/download/v1.19.2/aria2-1.19.2-win-xp-build1.7z"
$linkX86="https://github.com/aria2/aria2/releases/download/release-1.36.0/aria2-1.36.0-win-32bit-build1.zip"
$linkX64="https://github.com/aria2/aria2/releases/download/release-1.36.0/aria2-1.36.0-win-64bit-build1.zip"
$linkArm64="https://github.com/minnyres/aria2-windows-arm64/releases/download/v1.37.0/aria2_1.37.0_arm64.zip" # Not Tested
if (-not $arch) {
$currentArch = Get-CPU-Architecture-Suffix-for-Windows;
if ($currentArch -eq "arm64") {
if (Is-Intel-Emulation-Available 32) { $arch="x86"; }
if (Is-Intel-Emulation-Available 64) { $arch="x64"; }
} else {
$arch=$currentArch;
}
if (([System.Environment]::OSVersion.Version.Major) -eq 5) {
$arch="Xp";
}
}
$link = Get-Variable -Name "Link$arch" -Scope Local -ValueOnly
# $link="$($"Link$arch")"
# return "Not Implemented";
$archiveFileOnly="aria2c-$arch.$([System.IO.Path]::GetExtension($link).Trim([char]46))"
$downloadFolder = Combine-Path "$(Get-PS1-Repo-Downloads-Folder)" "aria2-setup"
$archiveFullName = Combine-Path $downloadFolder $archiveFileOnly
$plainFolder = Combine-Path "$(Get-PS1-Repo-Downloads-Folder)" "aria2-$arch"
$ret = Combine-Path "$plainFolder" "aria2c.exe"
Troubleshoot-Info "Download Link for [$arch] : $link"
Troubleshoot-Info "archiveFullName for [$arch] : $archiveFullName"
Troubleshoot-Info "plainFolder for [$arch] : $plainFolder"
$algorithm="SHA512"
if ((Is-File-Not-Empty "$ret") -and (Is-File-Not-Empty "$ret.$algorithm")) {
$hashActual = Get-Smarty-FileHash "$ret" $algorithm
$hashExpected = Get-Content -Path "$ret.$algorithm"
if ($hashActual -eq $hashExpected -and "$hashActual" -ne "") {
return $ret;
}
} else {
$isDownloadOk = Download-File-Managed "$link" "$archiveFullName" | Select -Last 1
if (-not $isDownloadOk) {
Write-Host "Error downloading $link" -ForeGroundColor Red;
}
else {
Troubleshoot-Info "Starting extract of '$archiveFullName'"
$isExtractOk = ExtractArchiveByDefault7zFull "$archiveFullName" "$plainFolder" "e" | Select -Last 1
Troubleshoot-Info "isExtractOk: $isExtractOk ($archiveFullName)"
if (-not $isExtractOk) {
Write-Host "Error extracting $archiveFullName" -ForeGroundColor Red;
} else {
$hashActual = Get-Smarty-FileHash "$ret" $algorithm
echo "$hashActual" > "$($ret).$algorithm"
return $ret;
}
}
}
return $null;
}
<#
https://github.com/q3aql/aria2-static-builds/releases/download/v1.19.2/aria2-1.19.2-win-xp-build1.7z
https://github.com/aria2/aria2/releases/download/release-1.36.0/aria2-1.36.0-win-32bit-build1.zip
https://github.com/aria2/aria2/releases/download/release-1.36.0/aria2-1.36.0-win-64bit-build1.zip
#>
# Include File: [\Includes\Get-CPU-Architecture-Suffix-for-Windows.ps1]
# x86 (0), MIPS (1), Alpha (2), PowerPC (3), ARM (5), ia64 (6) Itanium-based systems, x64 (9), ARM64 (12)
function Get-CPU-Architecture-Suffix-for-Windows-Implementation() {
$ret = Get-OS-Architecture-by-Registry
if ($ret) { return $ret; }
# on multiple sockets x64
$proc = Select-WMI-Objects "Win32_Processor";
$a = ($proc | Select -First 1).Architecture
if ($a -eq 0) { return "x86" };
if ($a -eq 1) { return "mips" };
if ($a -eq 2) { return "alpha" };
if ($a -eq 3) { return "powerpc" };
if ($a -eq 5) { return "arm" };
if ($a -eq 6) { return "ia64" };
if ($a -eq 9) {
# Is 32-bit system on 64-bit CPU?
# OSArchitecture: "ARM 64-bit Processor", "32-bit", "64-bit"
$os = Select-WMI-Objects "Win32_OperatingSystem";
$osArchitecture = ($os | Select -First 1).OSArchitecture
if ($osArchitecture -like "*32-bit*") { return "x86"; }
return "x64"
};
if ($a -eq 12) { return "arm64" };
return "";
}
function Get-CPU-Architecture-Suffix-for-Windows() {
if ($Global:CPUArchitectureSuffixforWindows -eq $null) { $Global:CPUArchitectureSuffixforWindows = Get-CPU-Architecture-Suffix-for-Windows-Implementation; }
return $Global:CPUArchitectureSuffixforWindows
}
function Get-OS-Architecture-by-Registry {
$regPath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$valueName = "PROCESSOR_ARCHITECTURE"
$rawArch = $null
try {
if (Test-Path $regPath) { $rawArch = (Get-ItemProperty -Path $regPath -Name $valueName -ErrorAction SilentlyContinue).$valueName }
} catch { $rawArch = $null }
switch ($rawArch) {
"AMD64" { return "x64" }
"x86" { return "x86" }
"ARM64" { return "arm64" }
"ARM" { return "arm" }
"IA64" { return "ia64" }
"EM64T" { return "x64" }
}
}
# Include File: [\Includes\Get-Cpu-Name.ps1]
function Get-Cpu-Name-Implementation {
$platform = Get-Os-Platform
if ($platform -eq "Windows") {
$proc = Select-WMI-Objects "Win32_Processor" | Select -First 1;
$ret = Normalize-Cpu-Name "$($proc.Name)".Trim()
return $ret
}
if ($platform -eq "MacOS") {
$ret = (& sysctl "-n" "machdep.cpu.brand_string" | Out-String-And-TrimEnd)
$ret = Normalize-Cpu-Name $ret
return $ret
}
if ($platform -eq "Linux") {
# TODO: Replace grep, awk, sed by NET
$shell="cat /proc/cpuinfo | grep -E '^(model name|Hardware)' | awk -F':' 'NR==1 {print `$2}' | sed -e 's/^[[:space:]]*//'"
$ret = "$(& bash -c "$shell" | Out-String-And-TrimEnd)"
if (-not $ret) {
$parts = @(
(Get-Nix-Uname-Value "-m"),
"$(& bash -c "getconf LONG_BIT" | Out-String-And-TrimEnd) bit"
);
$ret = ($parts | where { "$_" }) -join ", "
}
$ret = Normalize-Cpu-Name $ret
return $ret
}
$ret = $null;
try { $ret = Get-Nix-Uname-Value "-m"; } catch {}
$ret = Normalize-Cpu-Name $ret
if ($ret) { return "$ret"; }
return "Unknown"
}
function Normalize-Cpu-Name([string] $name) {
$ret = "$name".Replace("`r", " ").Replace("`n", " ").Replace("`t", " ")
while ($ret.IndexOf(" ") -ge 0) { $ret = "$ret".Replace(" ", " ") }
return $ret;
}
function Get-Cpu-Name {
[OutputType([string])] param([switch] $includeCoreCount)
if (-not $Global:_Cpu_Name) { $Global:_Cpu_Name = "$(Get-Cpu-Name-Implementation)"; }
$ret="$($Global:_Cpu_Name)"
if ($includeCoreCount) {
if ("$ret".Length -gt 0) { $ret += ", " }
$coreCount = [System.Environment]::ProcessorCount
if ($coreCount -eq 1) { $ret += "1 core" } else { $ret += "$coreCount cores" }
}
return $ret;
}
# Get-Cpu-Name -includeCoreCount
# Include File: [\Includes\Get-Folder-Size.ps1]
function Get-Folder-Size([string] $folder) {
if (Test-Path "$folder" -PathType Container) {
$subFolderItems = Get-ChildItem "$folder" -recurse -force | Where-Object {$_.PSIsContainer -eq $false} | Measure-Object -property Length -sum | Select-Object Sum
return $subFolderItems.sum;
}
}
# Include File: [\Includes\Get-Full7z-Exe-FullPath-for-Windows.ps1]
# arch: x86|x64|arm64
# version: 1604|2301
function Get-Full7z-Exe-FullPath-for-Windows([string] $arch, [string] $version = "2301") {
if (-not $arch) {
$currentArch = Get-CPU-Architecture-Suffix-for-Windows;
$arch = "x86"
if ($currentArch -eq "arm64") { $arch="arm64"; }
if ($currentArch -eq "x64") { $arch="x64"; }
# arm64 below 2201 is not supported
if ($arch -eq "arm64" -and (([int] $version) -lt 2201)) {
if (Is-Intel-Emulation-Available 32) { $arch="x86"; }
if (Is-Intel-Emulation-Available 64) { $arch="x64"; }
}
# v9.2 available as x86 only
if ((([int] $version) -eq 920)) {
$arch="x86";
}
}
# $suffix="-$arch"; if ($suffix -eq "-x86") { $suffix=""; }
# $link="https://www.7-zip.org/a/7z$($version)$($suffix).exe"
$versionLinks = $Full7zLinksMetadata_onWindows | where { "$($_.Ver)" -eq "$version" } | Select -First 1
$archLinks = $versionLinks."$($arch)Links"
if (-not $archLinks) {
TroubleShoot-Info "ERROR. Unknown links for full 7z v$($version) arch $arch"
}
$archiveFileOnly="7z-$version-$arch.exe"
$downloadFolder = Combine-Path "$(Get-PS1-Repo-Downloads-Folder)" "7z-Full-Setup"
$archiveFullName = Combine-Path $downloadFolder $archiveFileOnly
$plainFolder = Combine-Path "$(Get-PS1-Repo-Downloads-Folder)" "7z-Full-$arch-$version"
$ret = Combine-Path "$plainFolder" "7z.exe"
$algorithm="SHA512"
if ((Is-File-Not-Empty "$ret") -and (Is-File-Not-Empty "$ret.$algorithm")) {
$hashActual = Get-Smarty-FileHash "$ret" $algorithm
$hashExpected = Get-Content -Path "$ret.$algorithm"
if ($hashActual -eq $hashExpected -and "$hashActual" -ne "") {
return $ret;
}
} else {
$isDownloadOk = Download-File-FailFree $archiveFullName $archLinks | Select -Last 1
if (-not $isDownloadOk) {
Write-Host "Error downloading any link of [$archLinks]" -ForeGroundColor Red;
return $null;
}
$isExtractOk = ExtractArchiveBy7zMini "$archiveFullName" "$plainFolder" | Select -Last 1
popd
if (-not $isExtractOk) {
Write-Host "Error extracting $archiveFullName" -ForeGroundColor Red;
} else {
$hashActual = Get-Smarty-FileHash "$ret" $algorithm
echo "$hashActual" > "$($ret).$algorithm"
return $ret;
}
}
return $null;
}
function ExtractArchiveBy7zMini([string] $fromArchive, [string] $toDirectory) {
New-Item -Path "$($toDirectory)" -ItemType Directory -Force -EA SilentlyContinue | Out-Null
$mini7z = "$(Get-Mini7z-Exe-FullPath-for-Windows)"
$commandLine=@("x", "-y", "-o`"$($toDirectory)`"", "`"$fromArchive`"")
$singleCore7z=@(); $memInfo = Get-Memory-Info; $procCount = ([Environment]::ProcessorCount); if ($memInfo -and ($memInfo.Free) -and ($memInfo.Free -lt (640*$procCount))) { $singleCore7z=@("-mmt=1") }
$commandLine += $singleCore7z
Troubleshoot-Info "7z-mini: '$mini7z'; commandLine: '$commandLine' ('$fromArchive' ---> '$toDirectory')"
# ok on pwsh and powersheel
$prevPass = $PSNativeCommandArgumentPassing; $PSNativeCommandArgumentPassing = "Legacy"
& "$mini7z" @commandLine >$null
$PSNativeCommandArgumentPassing = $prevPass
$isExtractOk = $?;
return $isExtractOk;
}
function ExtractArchiveByDefault7zFull([string] $fromArchive, [string] $toDirectory, $extractCommand = "x") {
New-Item -Path "$($toDirectory)" -ItemType Directory -Force -EA SilentlyContinue | Out-Null
# pushd "$($toDirectory)"
$full7zExe = "$(Get-Full7z-Exe-FullPath-for-Windows)"
$commandLine = @("$extractCommand", "-y", "-o`"$($toDirectory)`"", "`"$fromArchive`"")
$singleCore7z=@(); $memInfo = Get-Memory-Info; $procCount = ([Environment]::ProcessorCount); if ($memInfo -and ($memInfo.Free) -and ($memInfo.Free -lt (640*$procCount))) { $singleCore7z=@("-mmt=1") }
$commandLine += $singleCore7z
Troubleshoot-Info "`"$fromArchive`" $([char]8594) " -Highlight "`"$($toDirectory)`"" " by `"$full7zExe`""
& "$full7zExe" $commandLine
$isExtractOk = $?;
return $isExtractOk;
}
<#
https://www.7-zip.org/a/7z2301-arm64.exe
https://www.7-zip.org/a/7z2301-x64.exe
https://www.7-zip.org/a/7z2301.exe
https://www.7-zip.org/a/7z2201-arm64.exe
https://www.7-zip.org/a/7z2201-x64.exe
https://www.7-zip.org/a/7z2201.exe
https://www.7-zip.org/a/7z1900-x64.exe
https://www.7-zip.org/a/7z1900.exe
https://www.7-zip.org/a/7z1604-x64.exe
https://www.7-zip.org/a/7z1604.exe
https://www.7-zip.org/a/7z920.exe
https://www.7-zip.org/a/7z920-arm.exe
https://www.7-zip.org/a/7zr.exe
#>
# Include File: [\Includes\Get-Github-Latest-Release.ps1]
function Get-Github-Latest-Release([string] $owner, [string] $repo) {
$queryLatest="https://api.github.com/repos/$owner/$repo/releases/latest" # "tag_name": "v3.227.2",
$qyeryResultFullName = Combine-Path (Get-PS1-Repo-Downloads-Folder) "Queries" "Github Latest Release" "$(([System.Guid]::NewGuid()).ToString("N")).json"
$isOk = Download-File-FailFree $qyeryResultFullName @($queryLatest)
if (-not $isOk) {
Write-Host "Error query latest version for '$owner/$repo'" -ForegroundColor Red
}
$jsonResult = Get-Content $qyeryResultFullName | ConvertFrom-Json
$ret = $jsonResult.tag_name;
if (-not $ret) {
Write-Host "Maflormed query latest version for '$owner/$repo'. Missing property 'tag_name'" -ForegroundColor Red
} else {
Remove-Item $qyeryResultFullName -Force
}
return $ret;
}
# Include File: [\Includes\Get-Github-Releases.ps1]
function Get-Github-Releases([string] $owner, [string] $repo) {
$url="https://api.github.com/repos/$owner/$repo/releases?per_page=128"
# https://api.github.com/repos/microsoft/azure-pipelines-agent/releases?per_page=128
$qyeryResultFullName = Combine-Path (Get-PS1-Repo-Downloads-Folder) "Queries" "Github Releases" "$(([System.Guid]::NewGuid()).ToString("N")).json"
$isOk = Download-File-FailFree $qyeryResultFullName @($url)
if (-not $isOk) {
Write-Host "Error query release list for '$owner/$repo'" -ForegroundColor Red
}
$jsonResult = Get-Content $qyeryResultFullName | ConvertFrom-Json
<#
"tag_name":"v3.230.0",
"target_commitish":"6ee2a6be8f5e0cccac6079e4fb42b5fe9f8de04e",
"name":"v3.230.0",
"draft":false,
"prerelease":true,
"created_at":"2023-11-03T02:33:23Z",
"published_at":"2023-11-07T11:17:01Z",
"tarball_url":"https://api.github.com/repos/microsoft/azure-pipelines-agent/tarball/v3.230.0",
"zipball_url":"https://api.github.com/repos/microsoft/azure-pipelines-agent/zipball/v3.230.0",
"body":"## Features\r\n - Add `AllowWorkDirectoryRepositories` knob (#4423)\r\n - Update process handler (#4425)\r\n - Check task deprecation (#4458)\r\n - Enable Domains for Pipeline Artifact (#4460)\r\n - dedupStoreHttpClient honors redirect timeout from client settings and update ADO lib to 0.5.227-262a3469 (#4504)\r\n\r\n## Bugs\r\n - Detect the OS and switch node runner if not supported for Node20 (#4470)\r\n - Revert \"Enable Domains for Pipeline Artifact\" (#4477)\r\n - Add capability to publish/download pipeline artifact in a different domain. (#4482)\r\n - Mount Workspace (#4483)\r\n\r\n## Misc\r\n\r\n\r\n\r\n## Agent Downloads\r\n\r\n| | Package | SHA-256 |\r\n| -------------- | ------- | ------- |\r\n| Windows x64 | [vsts-agent-win-x64-3.230.0.zip](https://vstsagentpackage.azureedge.net/agent/3.230.0/vsts-agent-win-x64-3.230.0.zip) | cbb21ea2ec0b64663c35d13f204e215cfe41cf2e3c8efff7c228fdab344d00de |\r\n| Windows x86 | [vsts-agent-win-x86-3.230.0.zip](https://vstsagentpackage.azureedge.net/agent/3.230.0/vsts-agent-win-x86-3.230.0.zip) | 7182a054b1f58c5d104f7b581fe00765c32f1bd544dc2bcc423d0159929f4692 |\r\n| macOS x64 | [vsts-agent-osx-x64-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/vsts-agent-osx-x64-3.230.0.tar.gz) | 988234fe3a1bbc6f79c3f6d94d70ea1908f2395ce6b685118d1dae983f03479e |\r\n| macOS ARM64 | [vsts-agent-osx-arm64-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/vsts-agent-osx-arm64-3.230.0.tar.gz) | 82f670482ffb45de2e533687c5eefa9506cbe0686edaa6a3c02487887729101c |\r\n| Linux x64 | [vsts-agent-linux-x64-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/vsts-agent-linux-x64-3.230.0.tar.gz) | bc222ec99ff675c1035efd0a086cea02adb5847ae7df8ee36e89db14aee8673d |\r\n| Linux ARM | [vsts-agent-linux-arm-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/vsts-agent-linux-arm-3.230.0.tar.gz) | f399e0ddceb10f09cd768c29e31fa51eb05c51c092e2392282e63795729f6a39 |\r\n| Linux ARM64 | [vsts-agent-linux-arm64-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/vsts-agent-linux-arm64-3.230.0.tar.gz) | 3c6fa98e26c7d8b19e8a35ca5b45a32122088a3bc12e817e7ccdead303893789 |\r\n| Linux musl x64 | [vsts-agent-linux-musl-x64-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/vsts-agent-linux-musl-x64-3.230.0.tar.gz) | 3461bef5756e452b920779b1f163cd194fa1971267acd582c2ad4870b1f611c2 |\r\n\r\nAfter Download:\r\n\r\n## Windows x64\r\n\r\n``` bash\r\nC:\\> mkdir myagent && cd myagent\r\nC:\\myagent> Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory(\"$HOME\\Downloads\\vsts-agent-win-x64-3.230.0.zip\", \"$PWD\")\r\n```\r\n\r\n## Windows x86\r\n\r\n``` bash\r\nC:\\> mkdir myagent && cd myagent\r\nC:\\myagent> Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory(\"$HOME\\Downloads\\vsts-agent-win-x86-3.230.0.zip\", \"$PWD\")\r\n```\r\n\r\n## macOS x64\r\n\r\n``` bash\r\n~/$ mkdir myagent && cd myagent\r\n~/myagent$ tar xzf ~/Downloads/vsts-agent-osx-x64-3.230.0.tar.gz\r\n```\r\n\r\n## macOS ARM64\r\n\r\n``` bash\r\n~/$ mkdir myagent && cd myagent\r\n~/myagent$ tar xzf ~/Downloads/vsts-agent-osx-arm64-3.230.0.tar.gz\r\n```\r\n\r\n## Linux x64\r\n\r\n``` bash\r\n~/$ mkdir myagent && cd myagent\r\n~/myagent$ tar xzf ~/Downloads/vsts-agent-linux-x64-3.230.0.tar.gz\r\n```\r\n\r\n## Linux ARM\r\n\r\n``` bash\r\n~/$ mkdir myagent && cd myagent\r\n~/myagent$ tar xzf ~/Downloads/vsts-agent-linux-arm-3.230.0.tar.gz\r\n```\r\n\r\n## Linux ARM64\r\n\r\n``` bash\r\n~/$ mkdir myagent && cd myagent\r\n~/myagent$ tar xzf ~/Downloads/vsts-agent-linux-arm64-3.230.0.tar.gz\r\n```\r\n\r\n## Alpine x64\r\n\r\n``` bash\r\n~/$ mkdir myagent && cd myagent\r\n~/myagent$ tar xzf ~/Downloads/vsts-agent-linux-musl-x64-3.230.0.tar.gz\r\n```\r\n\r\n***Note:*** Node 6 does not exist for Alpine.\r\n\r\n## Alternate Agent Downloads\r\n\r\nAlternate packages below do not include Node 6 and are only suitable for users who do not use Node 6 dependent tasks. \r\nSee [notes](docs/node6.md) on Node version support for more details.\r\n\r\n| | Package | SHA-256 |\r\n| ----------- | ------- | ------- |\r\n| Windows x64 | [pipelines-agent-win-x64-3.230.0.zip](https://vstsagentpackage.azureedge.net/agent/3.230.0/pipelines-agent-win-x64-3.230.0.zip) | f5bbae6dad8c39ea809db9b04abbcf3add37962d67ef9c67245a09fb536d38ca |\r\n| Windows x86 | [pipelines-agent-win-x86-3.230.0.zip](https://vstsagentpackage.azureedge.net/agent/3.230.0/pipelines-agent-win-x86-3.230.0.zip) | 00d5f1776767ead3e70036f63cdbd38a007b7d971c287a4d24d7346f4d3715a6 |\r\n| macOS x64 | [pipelines-agent-osx-x64-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/pipelines-agent-osx-x64-3.230.0.tar.gz) | e6e602c6664414b8a9b27a2df73511156d32a6bc76f8b4bb69aa960767aa9684 |\r\n| macOS ARM64 | [pipelines-agent-osx-arm64-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/pipelines-agent-osx-x64-3.230.0.tar.gz) | a00182572b1be649fe6836336bde3d4d3f79ceee42822fe44707afa9950b2232 |\r\n| Linux x64 | [pipelines-agent-linux-x64-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/pipelines-agent-linux-x64-3.230.0.tar.gz) | d46581abbf0eb5c3aef534825b51f92ade9d86a5b089b9489e84387070366d1b |\r\n| Linux ARM | [pipelines-agent-linux-arm-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/pipelines-agent-linux-arm-3.230.0.tar.gz) | 1dc871562bd6266567f7accced8d4a9ec3b4b85139891cf563a8fa305968ad40 |\r\n| Linux ARM64 | [pipelines-agent-linux-arm64-3.230.0.tar.gz](https://vstsagentpackage.azureedge.net/agent/3.230.0/pipelines-agent-linux-arm64-3.230.0.tar.gz) | 4ce243af0a09d5be2a6194b94d98c11fc323607b083ec5dcf3893bf67abb2dda |\r\n"
#>
$ret=@()
foreach($release in $jsonResult) {
$ret += New-Object PSObject -Property @{
Tag = $release.tag_name
Commit = $release.target_commitish
Name = $release.name
IsDraft = [bool] $release.draft
IsPrerelease = [bool] $release.prerelease
CreatedAt = $release.created_at
PublishedAt = $release.published_at
TarballUrl = $release.tarball_url
ZipballUrl = $release.zipball_url
}
}
if (-not ($ret | Select -First 1)) {
Write-Host "Empty release list for '$owner/$repo'" -ForegroundColor Red
} else {
Remove-Item $qyeryResultFullName -Force
}
return $ret | where { -not ($_.IsDraft) };
}
# Include File: [\Includes\Get-Installed-VC-Runtimes.ps1]
function Get-Installed-VC-Runtimes() {
$softwareFilter = { $_.name -like "*Visual C++*" -and $_.vendor -like "*Microsoft*" -and ($_.name -like "*Runtime*" -or $_.name -like "*Redistributable*")}
return Get-Speedy-Software-Product-List | where $softwareFilter
}
# Include File: [\Includes\Get-Memory-Info.ps1]
function Get-Memory-Info {
[OutputType([object])] param()
$platform = Get-Os-Platform
if ($platform -eq "Windows") {
$os = Select-WMI-Objects "Win32_OperatingSystem";
$mem=($os | Where { $_.FreePhysicalMemory } | Select FreePhysicalMemory,TotalVisibleMemorySize -First 1);
$total=[int] ($mem.TotalVisibleMemorySize / 1024);
$free=[int] ($mem.FreePhysicalMemory / 1024);
$wmiSwap = @(Select-WMI-Objects "Win32_PageFileUsage")
$swapCurrent = $wmiSwap | Measure-Object -property CurrentUsage -sum | % { $_.Sum } | Select -First 1
$swapPeak = $wmiSwap | Measure-Object -property PeakUsage -sum | % { $_.Sum } | Select -First 1
$swapAllocated = $wmiSwap | Measure-Object -property AllocatedBaseSize -sum | % { $_.Sum } | Select -First 1
if ($swapAllocated) {
$customDescription = ". Swap Usage: $(FormatNullableNumeric $swapCurrent) (peak $(FormatNullableNumeric $swapPeak)) of $(FormatNullableNumeric $swapAllocated) Mb"
}
}
if ($platform -eq "MacOS") {
$total=[long] (& sysctl -n hw.memsize | Out-String).TrimEnd(@([char]13,[char]10))
$total=[int] ($total/1024/1024)
$free=[long] (& vm_stat | grep "Pages free" | awk -v OFMT="%.0f" '{print (4 * $NF / 1024)}' | Out-String-And-TrimEnd)
$inactive=[long] (& vm_stat | grep "Pages inactive" | awk -v OFMT="%.0f" '{print (4 * $NF / 1024)}' | Out-String-And-TrimEnd)
$free = [int]$free + [int]$inactive;
# Write-Host "Mem Total: $total, Free: $free"
}
if ($platform -eq "Linux") {
# total: $2, $used: $3, shared: $5. free = total-(used+shared)
$total=[int] (& free -m | awk 'NR==2 {print $2}' | Out-String-And-TrimEnd)
$used =[int] (& free -m | awk 'NR==2 {print $3 + $5}' | Out-String-And-TrimEnd)
$free=$total-$used
$swapAllocated = [int] (& free -m | awk '$1 ~ /^[S|s]wap/ {print $2}' | Out-String-And-TrimEnd)
$swapCurrent = [int] (& free -m | awk '$1 ~ /^[S|s]wap/ {print $3}' | Out-String-And-TrimEnd)
if ($swapAllocated) {
$customDescription = ". Swap Usage: $(FormatNullableNumeric $swapCurrent) of $(FormatNullableNumeric $swapAllocated) Mb"
}
}
if ($total) {
$info="Total RAM: $($total.ToString("n0")) MB. Free: $($free.ToString("n0")) MB ($([Math]::Round($free * 100 / $total, 1))%)$customDescription";
$ret = @{
Total=$total;
Free=$free;
Description=$info;
}
if ($swapAllocated) {
$ret["SwapAllocated"] = $swapAllocated;
$ret["SwapCurrent"] = $swapCurrent;
}
return $ret;
}
<#
.OUTPUTS
Object with 3 properties: [int] Total, [int] Free, [string] Description
#>
}
function FormatNullableNumeric($n, $fractionalDigits = 0) {