-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathpostInstall.ps1
More file actions
1001 lines (884 loc) · 31.5 KB
/
postInstall.ps1
File metadata and controls
1001 lines (884 loc) · 31.5 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
# WelsonJS post-install script
# Namhyeon Go <gnh1201@catswords.re.kr>, and Catswords OSS contributors.
# Updated on: 2025-12-21
# https://github.com/gnh1201/welsonjs
# ================================
# PARAMETERS
# ================================
param(
[string]$TelemetryProvider = "",
[string]$TelemetryApiKey = "",
[string]$Version = "",
[string]$DistinctId = "",
[string]$Components = ""
)
# ================================
# LOGO
# ================================
$logo = @"
__ __ _ _ ____
\ \ / /__| |___ ___ _ __ | / ___|
\ \ /\ / / _ \ / __|/ _ \| '_ \ _ | \___ \
\ V V / __/ \__ \ (_) | | | | |_| |___) |
\_/\_/ \___|_|___/\___/|_| |_| \___/|____/
WelsonJS post-install script
https://github.com/gnh1201/welsonjs
"@
Write-Host $logo
# ================================
# SCRIPT ROOT RESOLUTION
# ================================
# Ensure $ScriptRoot is available even on older PowerShell
$ScriptRoot = if ($PSScriptRoot) {
$PSScriptRoot
}
elseif ($MyInvocation.MyCommand.Path) {
Split-Path -Parent $MyInvocation.MyCommand.Path
}
else {
(Get-Location).Path
}
# ================================
# LOAD DOWNLOAD URL TABLE (DownloadUrls.psd1 in /data folder)
# ================================
$DownloadUrls = @{}
$urlsFilePath = Join-Path $ScriptRoot "data/DownloadUrls.psd1"
if (Test-Path $urlsFilePath) {
try {
if (Get-Command Import-PowerShellDataFile -ErrorAction SilentlyContinue) {
$DownloadUrls = Import-PowerShellDataFile -Path $urlsFilePath
} else {
$DownloadUrls = Invoke-Expression (Get-Content $urlsFilePath -Raw) # Tested in Windows 8.1
}
}
catch {
Write-Host "[WARN] Failed to load DownloadUrls.psd1. Falling back to empty URL table."
$DownloadUrls = @{}
}
}
else {
Write-Host "[WARN] DownloadUrls.psd1 not found at: $urlsFilePath"
$DownloadUrls = @{}
}
function Get-DownloadUrl {
param(
[Parameter(Mandatory = $true)]
[string]$Component,
[Parameter(Mandatory = $true)]
[string]$Arch # x64, arm64, x86
)
$componentKey = $Component.ToLowerInvariant()
if (-not $DownloadUrls.ContainsKey($componentKey)) {
return $null
}
$entry = $DownloadUrls[$componentKey]
# Prefer arch-specific URL
if ($entry.ContainsKey($Arch)) {
return $entry[$Arch]
}
# Fallback to "any" (arch-independent)
if ($entry.ContainsKey("any")) {
return $entry["any"]
}
return $null
}
# ================================
# TELEMETRY
# ================================
if ($TelemetryProvider -and $TelemetryProvider.ToLower() -eq "posthog") {
# Skip telemetry if API key is missing
if (-not $TelemetryApiKey -or $TelemetryApiKey.Trim() -eq "") {
# No-op: continue script
}
else {
# Resolve distinct ID (fallback to machine name, then device UID)
$finalDistinctId = if ($DistinctId -and $DistinctId.Trim() -ne "") {
$DistinctId
} else {
# Attempt to get the machine name
$computerName = $env:COMPUTERNAME
if ($computerName -and $computerName.Trim() -ne "") {
$computerName
} else {
# Fall back to using the device UUID (if COMPUTERNAME is unavailable)
$deviceUid = (Get-WmiObject -Class Win32_ComputerSystemProduct).UUID
if ($deviceUid -and $deviceUid.Trim() -ne "") {
$deviceUid
} else {
# Optionally, generate a new UUID or use a predefined value if UUID is also unavailable
[guid]::NewGuid().ToString()
}
}
}
if ($finalDistinctId -and $finalDistinctId.Trim() -ne "") {
# Get current script file name
$scriptName = if (Get-Variable -Name PSCommandPath -ErrorAction SilentlyContinue) {
Split-Path $PSCommandPath -Leaf
} else {
Split-Path $MyInvocation.MyCommand.Path -Leaf
}
# Build single event payload for PostHog /i/v0/e endpoint
$body = @{
api_key = $TelemetryApiKey
event = "app_installed"
distinct_id = $finalDistinctId
properties = @{
product = "welsonjs"
version = $Version
os = "windows"
source = $scriptName
components = $Components # Keep raw string here
}
timestamp = (Get-Date).ToString("o") # ISO 8601 format
} | ConvertTo-Json -Depth 5
try {
Invoke-RestMethod `
-Uri "https://us.i.posthog.com/i/v0/e/" `
-Method Post `
-ContentType "application/json" `
-Body $body | Out-Null
}
catch {
# Ignore telemetry failure (installer must not break)
}
}
}
}
# ================================
# CONFIGURATION
# ================================
$AppName = "welsonjs"
$TargetDir = Join-Path $env:APPDATA $AppName
$TmpDir = Join-Path $env:TEMP "$AppName-downloads"
Write-Host ""
Write-Host "[*] Target directory : $TargetDir"
Write-Host "[*] Temporary directory: $TmpDir"
Write-Host ""
# Ensure base directories exist
New-Item -ItemType Directory -Path $TargetDir -Force | Out-Null
New-Item -ItemType Directory -Path $TmpDir -Force | Out-Null
# ================================
# COMPONENT SELECTION (SINGLE PARSE)
# ================================
# Convert Components (string) → array exactly once.
# Example: "python,curl,websocat"
# If empty → treat as "all selected" for backward compatibility.
$SelectedComponents = @()
$AllComponentsSelected = $true
if ($Components -and $Components.Trim() -ne "") {
$SelectedComponents =
$Components.Split(",") |
ForEach-Object { $_.Trim().ToLowerInvariant() }
$AllComponentsSelected = $false
}
function Test-ComponentSelected {
param(
[Parameter(Mandatory = $true)]
[string]$Name
)
if ($AllComponentsSelected) {
return $true
}
return $SelectedComponents -contains $Name.ToLowerInvariant()
}
Write-Host "[*] Selected components (raw): $Components"
if ($AllComponentsSelected) {
Write-Host "[*] Component filter : <none> (treat as ALL selected)"
} else {
Write-Host "[*] Component filter : $($SelectedComponents -join ', ')"
}
Write-Host ""
# ================================
# ARCHITECTURE DETECTION
# ================================
function Get-NativeArchitecture {
# https://learn.microsoft.com/windows/win32/cimwin32prov/win32-processor
$arch = $null
try {
$proc = Get-CimInstance -ClassName Win32_Processor -ErrorAction Stop |
Select-Object -First 1
switch ($proc.Architecture) {
0 { $arch = "x86" } # 32-bit Intel/AMD
5 { $arch = "arm32" } # 32-bit ARM
12 { $arch = "arm64" } # treat ARM as arm64 target
9 { $arch = "x64" } # 64-bit Intel/AMD
6 { $arch = "ia64" } # Intel Itanium
default { $arch = "x86" } # fallback
}
}
catch {
# Fallback: only 32/64 bit detection if WMI/CIM is not available
if ([System.Environment]::Is64BitOperatingSystem) {
$arch = "x64"
}
else {
$arch = "x86"
}
}
return $arch
}
$arch = Get-NativeArchitecture
Write-Host "[*] Detected architecture: $arch"
Write-Host ""
# ================================
# HELPER FUNCTIONS
# ================================
function Ensure-EmptyDirectory {
param(
[Parameter(Mandatory = $true)]
[string]$Path
)
# If a file exists at this path, delete it
if (Test-Path $Path -PathType Leaf) {
Write-Host "[WARN] File exists at '$Path'. Removing..."
Remove-Item -Path $Path -Force
}
# Ensure a directory exists at this path
if (-not (Test-Path $Path -PathType Container)) {
Write-Host "[*] Creating directory: $Path"
New-Item -ItemType Directory -Path $Path -Force | Out-Null
}
}
function Download-File {
param(
[Parameter(Mandatory = $true)]
[string]$Url,
[Parameter(Mandatory = $true)]
[string]$DestinationPath
)
Write-Host "[*] Downloading:"
Write-Host " $Url"
Write-Host " -> $DestinationPath"
# Fix TLS connectivity issues (Tested in Windows 8.1)
try {
$protocol = [Net.SecurityProtocolType]::Tls12 -bor `
[Net.SecurityProtocolType]::Tls11 -bor `
[Net.SecurityProtocolType]::Tls
try {
$protocol = $protocol -bor [Enum]::Parse([Net.SecurityProtocolType], 'Tls13')
} catch {}
[Net.ServicePointManager]::SecurityProtocol = $protocol
}
catch {
Write-Host "[WARN] TLS configuration failed: $($_.Exception.Message)"
}
# Ensure destination directory exists
$destDir = Split-Path -Parent $DestinationPath
if ($destDir -and -not (Test-Path $destDir)) {
New-Item -ItemType Directory -Path $destDir -Force | Out-Null
}
$maxRetries = 3
$attempt = 0
$success = $false
while (-not $success -and $attempt -lt $maxRetries) {
$attempt++
try {
Invoke-WebRequest -Uri $Url -OutFile $DestinationPath -UseBasicParsing
$success = $true
}
catch {
Write-Host "[WARN] Download failed (attempt $attempt of $maxRetries): $($_.Exception.Message)"
if ($attempt -lt $maxRetries) {
Start-Sleep -Seconds 5
}
}
}
if (-not $success) {
Write-Host "[WARN] PowerShell download failed. Falling back to curl."
$curlPath = Join-Path $ScriptRoot "bin\x86\curl.exe"
if (-not (Test-Path $curlPath)) {
throw "curl not found at $curlPath"
}
$curlArgs = @(
"-L"
"--fail"
"--retry", "3"
"--retry-delay", "5"
"-o", $DestinationPath
$Url
)
$proc = Start-Process -FilePath $curlPath -ArgumentList $curlArgs -NoNewWindow -Wait -PassThru
if ($proc.ExitCode -ne 0 -or -not (Test-Path $DestinationPath)) {
throw "curl download failed with exit code $($proc.ExitCode)."
}
}
}
function Invoke-7zr {
param(
[Parameter(Mandatory = $true)]
[string[]]$Arguments,
[Parameter(Mandatory = $false)]
[string[]]$PipeToArguments
)
$sevenZip = Join-Path $ScriptRoot "bin\x86\7zr.exe"
if (-not (Test-Path $sevenZip)) {
throw "7zr.exe is missing: $sevenZip"
}
Write-Host "[INFO] Using 7zr.exe:"
Write-Host " $sevenZip"
Write-Host "[DEBUG] 7zr args:"
Write-Host " $($Arguments -join ' ')"
if ($PipeToArguments) {
Write-Host "[DEBUG] 7zr pipe-to args:"
Write-Host " $($PipeToArguments -join ' ')"
& $sevenZip @Arguments | & $sevenZip @PipeToArguments
}
else {
& $sevenZip @Arguments
}
if ($LASTEXITCODE -ne 0) {
throw "7zr exited with code $LASTEXITCODE."
}
}
function Extract-CompressedFile {
param(
[Parameter(Mandatory = $true)]
[string]$CompressedPath,
[Parameter(Mandatory = $true)]
[string]$DestinationDirectory
)
Write-Host "[*] Extracting compressed file:"
Write-Host " $CompressedPath"
Write-Host " -> $DestinationDirectory"
Ensure-EmptyDirectory -Path $DestinationDirectory
$tmpExtractDir = Join-Path $DestinationDirectory "_tmp_extract"
Ensure-EmptyDirectory -Path $tmpExtractDir
$extractedOk = $false
$zipErrorMsg = $null
# Try ZipFile first
try {
Add-Type -AssemblyName System.IO.Compression.FileSystem -ErrorAction Stop
[System.IO.Compression.ZipFile]::ExtractToDirectory($CompressedPath, $tmpExtractDir)
$extractedOk = $true
}
catch {
$zipErrorMsg = $_.Exception.Message
Write-Host "[WARN] ZipFile extraction failed. Falling back to 7zr.exe."
Write-Host " $zipErrorMsg"
}
# Fallback: 7zr.exe
if (-not $extractedOk) {
Invoke-7zr -Arguments @("x", $CompressedPath, "-o$tmpExtractDir", "-y")
$extractedOk = $true
}
# Detect root folder unwrap
$entries = Get-ChildItem -Path $tmpExtractDir -Force
$SourceRoot = $tmpExtractDir
if ($entries.Count -eq 1 -and $entries[0].PSIsContainer) {
$SourceRoot = $entries[0].FullName
Write-Host "[*] Detected single root folder inside archive: $($entries[0].Name)"
Write-Host "[*] Unwrapping folder content..."
}
else {
Write-Host "[*] Extracting multi-item archive (no root folder unwrapping needed)."
}
# Move items into final destination
Get-ChildItem -Path $SourceRoot -Force | ForEach-Object {
$targetPath = Join-Path $DestinationDirectory $_.Name
if (Test-Path $targetPath) {
Remove-Item -Path $targetPath -Recurse -Force
}
Move-Item -Path $_.FullName -Destination $targetPath
}
Remove-Item -Path $tmpExtractDir -Recurse -Force
}
function Extract-TarGzArchive {
param(
[Parameter(Mandatory = $true)]
[string]$ArchivePath,
[Parameter(Mandatory = $true)]
[string]$DestinationDirectory
)
Write-Host "[*] Extracting TAR.GZ archive:"
Write-Host " $ArchivePath"
Write-Host " -> $DestinationDirectory"
Ensure-EmptyDirectory -Path $DestinationDirectory
# Try tar first
$tarCommand = Get-Command tar -ErrorAction SilentlyContinue
if ($tarCommand) {
Write-Host "[DEBUG] tar command:"
Write-Host " tar -xzf `"$ArchivePath`" -C `"$DestinationDirectory`""
& tar -xzf "$ArchivePath" -C "$DestinationDirectory"
if ($LASTEXITCODE -ne 0) {
throw "tar exited with code $LASTEXITCODE."
}
return
}
Write-Host "[WARN] 'tar' not found. Falling back to 7zr.exe."
Invoke-7zr `
-Arguments @("x", $ArchivePath, "-so") `
-PipeToArguments @("x", "-ttar", "-si", "-o$DestinationDirectory", "-y")
}
# ================================
# COMPRESSED / INSTALLER PATHS
# ================================
$PythonCompressed = Join-Path $TmpDir "python.zip"
$CurlCompressed = Join-Path $TmpDir "curl.zip"
$YaraCompressed = Join-Path $TmpDir "yara.zip"
$WamrArchive = Join-Path $TmpDir "wamr.tar.gz"
$WebsocatCompressed = Join-Path $TmpDir "websocat.zip"
$ArtifactsCompressed = Join-Path $TmpDir "artifacts.zip"
$GtkRuntimeInstaller = Join-Path $TmpDir "gtk-runtime.exe"
$TessdataCompressed = Join-Path $TmpDir "tessdata.zip"
$TessdataBestCompressed = Join-Path $TmpDir "tessdata_best.zip"
$TessdataFastCompressed = Join-Path $TmpDir "tessdata_fast.zip"
$NpcapInstaller = Join-Path $TmpDir "npcap-setup.exe"
$NmapInstaller = Join-Path $TmpDir "nmap-setup.exe"
$GtkServerCompressed = Join-Path $TmpDir "gtkserver.zip"
$WinDivertCompressed = Join-Path $TmpDir "windivert.zip"
$AndroidPlatformToolsCompressed = Join-Path $TmpDir "android-platform-tools.zip"
# ================================
# DOWNLOAD PHASE
# ================================
try {
# Python (component: python)
if (Test-ComponentSelected -Name "python") {
$url = Get-DownloadUrl -Component "python" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $PythonCompressed
}
else {
Write-Host "[*] Python URL not available for arch: $arch. Skipping download."
}
}
else {
Write-Host "[*] Python component not selected. Skipping download."
}
# curl (component: curl)
if (Test-ComponentSelected -Name "curl") {
$url = Get-DownloadUrl -Component "curl" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $CurlCompressed
}
else {
Write-Host "[*] curl URL not available for arch: $arch. Skipping download."
}
}
else {
Write-Host "[*] curl component not selected. Skipping download."
}
# YARA (component: yara)
if (Test-ComponentSelected -Name "yara") {
$url = Get-DownloadUrl -Component "yara" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $YaraCompressed
}
else {
Write-Host "[*] YARA URL not available for arch: $arch. Skipping download."
}
}
else {
Write-Host "[*] YARA component not selected. Skipping download."
}
# WAMR (component: wamr)
if (Test-ComponentSelected -Name "wamr") {
$url = Get-DownloadUrl -Component "wamr" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $WamrArchive
}
else {
Write-Host "[*] WAMR URL not available for arch: $arch. Skipping download."
}
}
else {
Write-Host "[*] WAMR component not selected. Skipping download."
}
# websocat (component: websocat)
if (Test-ComponentSelected -Name "websocat") {
$url = Get-DownloadUrl -Component "websocat" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $WebsocatCompressed
}
else {
Write-Host "[*] websocat URL not available for arch: $arch. Skipping download."
}
}
else {
Write-Host "[*] websocat component not selected. Skipping download."
}
# artifacts (component: artifacts)
if (Test-ComponentSelected -Name "artifacts") {
$url = Get-DownloadUrl -Component "artifacts" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $ArtifactsCompressed
}
else {
Write-Host "[*] artifacts URL not available for arch: $arch. Skipping download."
}
}
else {
Write-Host "[*] artifacts component not selected. Skipping download."
}
# GTK3 runtime (component: gtk3runtime)
if (Test-ComponentSelected -Name "gtk3runtime") {
$url = Get-DownloadUrl -Component "gtk3runtime" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $GtkRuntimeInstaller
}
else {
Write-Host "[*] gtk3runtime URL not available for arch: $arch. Skipping download."
}
}
else {
Write-Host "[*] gtk3runtime component not selected. Skipping download."
}
# GTK server (component: gtkserver)
if (Test-ComponentSelected -Name "gtkserver") {
$url = Get-DownloadUrl -Component "gtkserver" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $GtkServerCompressed
}
else {
Write-Host "[*] gtkserver URL not available for arch: $arch. Skipping download."
}
}
else {
Write-Host "[*] gtkserver component not selected. Skipping download."
}
# tessdata (component: tessdata)
if (Test-ComponentSelected -Name "tessdata") {
$url = Get-DownloadUrl -Component "tessdata" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $TessdataCompressed
}
else {
Write-Host "[*] tessdata URL not available. Skipping download."
}
}
else {
Write-Host "[*] tessdata component not selected. Skipping download."
}
# tessdata_best (component: tessdata_best)
if (Test-ComponentSelected -Name "tessdata_best") {
$url = Get-DownloadUrl -Component "tessdata_best" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $TessdataBestCompressed
}
else {
Write-Host "[*] tessdata_best URL not available. Skipping download."
}
}
else {
Write-Host "[*] tessdata_best component not selected. Skipping download."
}
# tessdata_fast (component: tessdata_fast)
if (Test-ComponentSelected -Name "tessdata_fast") {
$url = Get-DownloadUrl -Component "tessdata_fast" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $TessdataFastCompressed
}
else {
Write-Host "[*] tessdata_fast URL not available. Skipping download."
}
}
else {
Write-Host "[*] tessdata_fast component not selected. Skipping download."
}
# Nmap bundle (component: nmap) – includes Npcap + Nmap installer
if (Test-ComponentSelected -Name "nmap") {
# Npcap
$url = Get-DownloadUrl -Component "npcap" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $NpcapInstaller
}
else {
Write-Host "[*] npcap URL not available. Skipping npcap download."
}
# Nmap
$url = Get-DownloadUrl -Component "nmap" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $NmapInstaller
}
else {
Write-Host "[*] nmap URL not available. Skipping nmap download."
}
}
else {
Write-Host "[*] nmap component not selected. Skipping Npcap/Nmap download."
}
# windivert (component: windivert)
if (Test-ComponentSelected -Name "windivert") {
$url = Get-DownloadUrl -Component "windivert" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $WinDivertCompressed
}
else {
Write-Host "[*] WinDivert URL not available. Skipping download."
}
}
else {
Write-Host "[*] WinDivert component not selected. Skipping download."
}
# Android Platform Tools (component: android_platform_tools)
if (Test-ComponentSelected -Name "android_platform_tools") {
$url = Get-DownloadUrl -Component "android_platform_tools" -Arch $arch
if ($url) {
Download-File -Url $url -DestinationPath $AndroidPlatformToolsCompressed
}
else {
Write-Host "[*] Android Platform Tools URL not available. Skipping download."
}
}
else {
Write-Host "[*] Android Platform Tools component not selected. Skipping download."
}
}
catch {
Write-Host "[FATAL] Download phase failed."
if ($_ -is [System.Exception]) {
Write-Host $_.Exception.Message
} else {
Write-Host $_
}
exit 1
}
# ================================
# EXTRACT / INSTALL PHASE
# ================================
try {
# Python (component: python)
if (Test-ComponentSelected -Name "python") {
if (Test-Path $PythonCompressed) {
Extract-CompressedFile `
-CompressedPath $PythonCompressed `
-DestinationDirectory (Join-Path $TargetDir "python")
}
else {
Write-Host "[WARN] Python archive not found. Skipping installation."
}
}
else {
Write-Host "[*] Python component not selected. Skipping installation."
}
# curl (component: curl)
if (Test-ComponentSelected -Name "curl") {
if (Test-Path $CurlCompressed) {
Extract-CompressedFile `
-CompressedPath $CurlCompressed `
-DestinationDirectory (Join-Path $TargetDir "curl")
}
else {
Write-Host "[WARN] curl archive not found. Skipping installation."
}
}
else {
Write-Host "[*] curl component not selected. Skipping installation."
}
# YARA (component: yara)
if (Test-ComponentSelected -Name "yara") {
if (Test-Path $YaraCompressed) {
Extract-CompressedFile `
-CompressedPath $YaraCompressed `
-DestinationDirectory (Join-Path $TargetDir "yara")
}
else {
Write-Host "[WARN] YARA archive not found. Skipping installation."
}
}
else {
Write-Host "[*] YARA component not selected. Skipping installation."
}
# WAMR (component: wamr, TAR.GZ)
if (Test-ComponentSelected -Name "wamr") {
if (Test-Path $WamrArchive) {
Extract-TarGzArchive `
-ArchivePath $WamrArchive `
-DestinationDirectory (Join-Path $TargetDir "wamr")
}
else {
Write-Host "[WARN] WAMR archive not found. Skipping installation."
}
}
else {
Write-Host "[*] WAMR component not selected. Skipping installation."
}
# websocat (component: websocat)
if (Test-ComponentSelected -Name "websocat") {
if (Test-Path $WebsocatCompressed) {
Extract-CompressedFile `
-CompressedPath $WebsocatCompressed `
-DestinationDirectory (Join-Path $TargetDir "websocat")
}
else {
Write-Host "[WARN] websocat archive not found. Skipping installation."
}
}
else {
Write-Host "[*] websocat component not selected. Skipping installation."
}
# artifacts (component: artifacts)
if (Test-ComponentSelected -Name "artifacts") {
if (Test-Path $ArtifactsCompressed) {
Extract-CompressedFile `
-CompressedPath $ArtifactsCompressed `
-DestinationDirectory (Join-Path $TargetDir "bin")
}
else {
Write-Host "[WARN] artifacts archive not found. Skipping installation."
}
}
else {
Write-Host "[*] artifacts component not selected. Skipping installation."
}
# GTK3 runtime (component: gtk3runtime) – run installer and wait
if (Test-ComponentSelected -Name "gtk3runtime") {
if (Test-Path $GtkRuntimeInstaller) {
Write-Host "[*] Running GTK runtime installer (wait): $GtkRuntimeInstaller"
Start-Process -FilePath $GtkRuntimeInstaller -Wait -ErrorAction Stop
}
else {
Write-Host "[WARN] GTK runtime installer not found. Skipping."
}
}
else {
Write-Host "[*] gtk3runtime component not selected. Skipping installation."
}
# GTK server (component: gtkserver) – extract ZIP into AppData
if (Test-ComponentSelected -Name "gtkserver") {
if (Test-Path $GtkServerCompressed) {
Extract-CompressedFile `
-CompressedPath $GtkServerCompressed `
-DestinationDirectory (Join-Path $TargetDir "gtkserver")
}
else {
Write-Host "[WARN] gtkserver archive not found. Skipping installation."
}
}
else {
Write-Host "[*] gtkserver component not selected. Skipping installation."
}
# tessdata (component: tessdata)
if (Test-ComponentSelected -Name "tessdata") {
if (Test-Path $TessdataCompressed) {
Extract-CompressedFile `
-CompressedPath $TessdataCompressed `
-DestinationDirectory (Join-Path $TargetDir "tessdata")
}
else {
Write-Host "[WARN] tessdata archive not found. Skipping installation."
}
}
else {
Write-Host "[*] tessdata component not selected. Skipping installation."
}
# tessdata_best (component: tessdata_best)
if (Test-ComponentSelected -Name "tessdata_best") {
if (Test-Path $TessdataBestCompressed) {
Extract-CompressedFile `
-CompressedPath $TessdataBestCompressed `
-DestinationDirectory (Join-Path $TargetDir "tessdata_best")
}
else {
Write-Host "[WARN] tessdata_best archive not found. Skipping installation."
}
}
else {
Write-Host "[*] tessdata_best component not selected. Skipping installation."
}
# tessdata_fast (component: tessdata_fast)
if (Test-ComponentSelected -Name "tessdata_fast") {
if (Test-Path $TessdataFastCompressed) {
Extract-CompressedFile `
-CompressedPath $TessdataFastCompressed `
-DestinationDirectory (Join-Path $TargetDir "tessdata_fast")
}
else {
Write-Host "[WARN] tessdata_fast archive not found. Skipping installation."
}
}
else {
Write-Host "[*] tessdata_fast component not selected. Skipping installation."
}
# Nmap bundle (component: nmap) – Npcap → Nmap → VC_redist.x86.exe
if (Test-ComponentSelected -Name "nmap") {
# Npcap
if (Test-Path $NpcapInstaller) {
Write-Host "[*] Running Npcap installer (wait): $NpcapInstaller"
Start-Process -FilePath $NpcapInstaller -Wait -ErrorAction Stop
}
else {
Write-Host "[WARN] Npcap installer not found. Skipping Npcap."
}
# Nmap
if (Test-Path $NmapInstaller) {
Write-Host "[*] Running Nmap installer (wait): $NmapInstaller"
Start-Process -FilePath $NmapInstaller -Wait -ErrorAction Stop
}
else {
Write-Host "[WARN] Nmap installer not found. Skipping Nmap."
}
# Find and run VC_redist.x86.exe inside Nmap installation directory
$searchDirs = @()
if (${env:ProgramFiles(x86)}) {
$searchDirs += (Join-Path ${env:ProgramFiles(x86)} "Nmap")
}
if ($env:ProgramFiles) {
$searchDirs += (Join-Path $env:ProgramFiles "Nmap")
}
$vcRedist = $null
foreach ($dir in $searchDirs) {
if (Test-Path $dir) {
$candidate = Get-ChildItem -Path $dir -Filter "vc_redist.x86.exe" -Recurse -ErrorAction SilentlyContinue |
Select-Object -First 1
if ($candidate) {
$vcRedist = $candidate
break
}
}
}
if ($vcRedist) {
Write-Host "[*] Running VC_redist.x86 installer: $($vcRedist.FullName)"
Start-Process -FilePath $vcRedist.FullName -Wait -ErrorAction SilentlyContinue
}
else {
Write-Host "[WARN] VC_redist.x86.exe not found under expected Nmap directories."
}
}
else {
Write-Host "[*] nmap component not selected. Skipping Npcap/Nmap installation."
}
# windivert (component: windivert)
if (Test-ComponentSelected -Name "windivert") {
if (Test-Path $WinDivertCompressed) {
Extract-CompressedFile `
-CompressedPath $WinDivertCompressed `
-DestinationDirectory (Join-Path $TargetDir "windivert")
}
else {
Write-Host "[WARN] WinDivert archive not found. Skipping installation."
}
}
else {
Write-Host "[*] WinDivert component not selected. Skipping installation."
}
# Android Platform Tools (component: android_platform_tools)
if (Test-ComponentSelected -Name "android_platform_tools") {
if (Test-Path $AndroidPlatformToolsCompressed) {
Extract-CompressedFile `
-CompressedPath $AndroidPlatformToolsCompressed `
-DestinationDirectory (Join-Path $TargetDir "android_platform_tools")
}
else {
Write-Host "[WARN] Android Platform Tools archive not found. Skipping installation."
}
}
else {
Write-Host "[*] Android Platform Tools component not selected. Skipping installation."
}
}
catch {
Write-Host "[FATAL] Extraction/installation phase failed."
if ($_ -is [System.Exception]) {
Write-Host $_.Exception.Message
} else {
Write-Host $_
}
exit 1
}
# ================================
# FINISH
# ================================
Write-Host "[*] Installation completed successfully."
Write-Host "[*] Installed into: $TargetDir"
Write-Host ""