-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbuild.ps1
More file actions
178 lines (142 loc) · 6.68 KB
/
Copy pathbuild.ps1
File metadata and controls
178 lines (142 loc) · 6.68 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
<#
.SYNOPSIS
SysWarden Micro-Modular Compiler (Windows/PowerShell 7+ Edition)
.DESCRIPTION
Compiles individual bash function scripts into a single universal deployment artifact.
Guarantees strict Unix (LF) line endings and UTF-8 encoding.
#>
$ErrorActionPreference = 'Stop'
$DistDir = "dist"
$OutputFile = "$DistDir/install-syswarden.sh"
Write-Host "[*] Initializing SysWarden Universal Build (PowerShell Edition)..." -ForegroundColor Cyan
Write-Host "[*] Compiling syswarden-core (Golang WAF)..." -ForegroundColor Cyan
if (!(Get-Command "go" -ErrorAction SilentlyContinue)) {
Write-Host "[-] WARNING: Golang is not installed or not in PATH." -ForegroundColor Yellow
Write-Host "[-] Attempting automatic installation of Golang via winget..." -ForegroundColor Cyan
if (Get-Command "winget" -ErrorAction SilentlyContinue) {
winget install GoLang.Go --silent --accept-source-agreements --accept-package-agreements
# Refresh environment variables to detect Go in the current session
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
if (!(Get-Command "go" -ErrorAction SilentlyContinue)) {
Write-Host "[-] ERROR: Golang automatic installation failed. Please restart your PowerShell session or install manually: https://go.dev/dl/" -ForegroundColor Red
exit 1
}
Write-Host "[+] Golang successfully installed." -ForegroundColor Green
} else {
Write-Host "[-] ERROR: winget is not available on this system." -ForegroundColor Red
Write-Host "[-] Please install Go manually: https://go.dev/dl/" -ForegroundColor Red
exit 1
}
}
if (Test-Path "src/core/syswarden-cli/main.go") {
Write-Host "[*] Compiling syswarden-cli (Golang CLI Orchestrator)..." -ForegroundColor Cyan
$GoCliDir = "src/core/syswarden-cli"
$OriginalLocation = Get-Location
Set-Location $GoCliDir
try { go mod tidy 2>$null } catch {}
$env:GOOS="linux"
$env:GOARCH="amd64"
$env:CGO_ENABLED="0"
go build -ldflags="-s -w" -o syswarden-cli .
Set-Location $OriginalLocation
if (!(Test-Path "$DistDir/bin")) {
New-Item -ItemType Directory -Force -Path "$DistDir/bin" | Out-Null
}
Copy-Item -Path "$GoCliDir/syswarden-cli" -Destination "$DistDir/bin/syswarden-cli" -Force
Write-Host "[+] Golang CLI compiled and copied to $DistDir/bin/" -ForegroundColor Green
} else {
Write-Host "[-] WARNING: syswarden-cli not found. Skipping Go build." -ForegroundColor Yellow
}
if (Test-Path "src/core/syswarden-core/main.go") {
$GoCoreDir = "src/core/syswarden-core"
$OriginalLocation = Get-Location
Set-Location $GoCoreDir
# Init and Tidy
if (!(Test-Path "go.mod")) {
try { go mod init syswarden-core 2>$null } catch {}
}
try { go mod tidy 2>$null } catch {}
# Build for Linux (Cross-Compilation)
$env:GOOS="linux"
$env:GOARCH="amd64"
$env:CGO_ENABLED="0"
go build -ldflags="-s -w" -o syswarden-core .
Set-Location $OriginalLocation
if (!(Test-Path "$DistDir/bin")) {
New-Item -ItemType Directory -Force -Path "$DistDir/bin" | Out-Null
}
Copy-Item -Path "$GoCoreDir/syswarden-core" -Destination "$DistDir/bin/syswarden-core" -Force
Copy-Item -Path "$GoCoreDir/signatures.json" -Destination "$DistDir/signatures.json" -Force
Write-Host "[+] Golang WAF compiled and copied to $DistDir/bin/" -ForegroundColor Green
} else {
Write-Host "[-] WARNING: syswarden-core not found. Skipping Go build." -ForegroundColor Yellow
}
Write-Host "[*] Compiling syswarden-tui (Golang TUI)..." -ForegroundColor Cyan
if (Test-Path "src/core/syswarden-tui/main.go") {
$GoTuiDir = "src/core/syswarden-tui"
$OriginalLocation = Get-Location
Set-Location $GoTuiDir
# Init and Tidy
if (!(Test-Path "go.mod")) {
try { go mod init syswarden-tui 2>$null } catch {}
}
try { go mod tidy 2>$null } catch {}
# Build for Linux (Cross-Compilation)
$env:GOOS="linux"
$env:GOARCH="amd64"
$env:CGO_ENABLED="0"
go build -ldflags="-s -w" -o syswarden-tui .
Set-Location $OriginalLocation
Copy-Item -Path "$GoTuiDir/syswarden-tui" -Destination "$DistDir/bin/syswarden-tui" -Force
Write-Host "[+] Golang TUI compiled and copied to $DistDir/bin/" -ForegroundColor Green
} else {
Write-Host "[-] WARNING: syswarden-tui not found. Skipping Go build." -ForegroundColor Yellow
}
Write-Host "[*] Compiling SysWarden Native Go Modules for FreeBSD..." -ForegroundColor Cyan
if (!(Test-Path "$DistDir/freebsd/bin")) {
New-Item -ItemType Directory -Force -Path "$DistDir/freebsd/bin" | Out-Null
}
$env:GOOS="freebsd"
$env:GOARCH="amd64"
$env:CGO_ENABLED="0"
Set-Location "src/core/syswarden-cli"
go build -ldflags="-s -w" -o ../../../dist/freebsd/bin/syswarden-cli .
Set-Location ../../../
Write-Host "[*] Compiling SysWarden Native Go Modules for Linux ARM64..." -ForegroundColor Cyan
if (!(Test-Path "$DistDir/linux-arm64/bin")) {
New-Item -ItemType Directory -Force -Path "$DistDir/linux-arm64/bin" | Out-Null
}
$env:GOOS="linux"
$env:GOARCH="arm64"
$env:CGO_ENABLED="0"
Set-Location "src/core/syswarden-cli"
go build -ldflags="-s -w" -o ../../../dist/linux-arm64/bin/syswarden-cli .
Set-Location ../../../
Set-Location "src/core/syswarden-core"
go build -ldflags="-s -w" -o ../../../dist/linux-arm64/bin/syswarden-core .
Set-Location ../../../
Copy-Item -Path "src/core/syswarden-core/signatures.json" -Destination "$DistDir/linux-arm64/signatures.json" -Force
Set-Location "src/core/syswarden-tui"
go build -ldflags="-s -w" -o ../../../dist/linux-arm64/bin/syswarden-tui .
Set-Location ../../../
Write-Host "[+] Linux ARM64 Compilation successful." -ForegroundColor Green
Set-Location "src/core/syswarden-core"
go build -ldflags="-s -w" -o ../../../dist/freebsd/bin/syswarden-core .
Set-Location ../../../
Set-Location "src/core/syswarden-tui"
go build -ldflags="-s -w" -o ../../../dist/freebsd/bin/syswarden-tui .
Set-Location ../../../
Write-Host "[+] FreeBSD Compilation successful." -ForegroundColor Green
# Create dist directory if it doesn't exist
if (!(Test-Path $DistDir)) {
New-Item -ItemType Directory -Force -Path $DistDir | Out-Null
}
# ==========================================
# FINAL COMPILATION VERIFICATION
# ==========================================
if ((Test-Path "$DistDir/bin/syswarden-cli") -and (Test-Path "$DistDir/bin/syswarden-core")) {
Write-Host "[+] Build complete. Artifacts successfully compiled in $DistDir/bin/" -ForegroundColor Green
} else {
Write-Host "[-] ERROR: Missing expected binaries. Build failed." -ForegroundColor Red
exit 1
}