-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
113 lines (95 loc) · 3.03 KB
/
Copy pathbuild.ps1
File metadata and controls
113 lines (95 loc) · 3.03 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
param (
[string]$Action = "all",
[string]$RootPath = "$PSScriptRoot",
[string]$ParentPath = ""
)
$ErrorActionPreference = "Stop"
if (-not $RootPath) {
$RootPath = (Get-Item .).FullName
}
if (-not $ParentPath) {
$ParentPath = (Get-Item (Join-Path $RootPath "..")).FullName
}
# Root and output
$BinPath = Join-Path $RootPath "bin"
$ExePath = Join-Path $BinPath "OpenSysKit.exe"
# Parent path files
$CertPath = Join-Path $ParentPath "WinDriverLoader.pfx"
$CertPassPath = Join-Path $ParentPath "password.txt"
function Get-SignTool {
$paths = @(
"C:\Program Files (x86)\Windows Kits\10\bin\10.0.*.0\x64\signtool.exe",
"C:\Program Files (x86)\Windows Kits\10\bin\x64\signtool.exe",
"C:\Program Files (x86)\Windows Kits\8.1\bin\x64\signtool.exe"
)
foreach ($p in $paths) {
$resolved = Get-ChildItem $p -ErrorAction SilentlyContinue | Select-Object -Last 1
if ($resolved) {
return $resolved.FullName
}
}
return $null
}
function Build {
if (-not (Test-Path $BinPath)) {
New-Item -ItemType Directory -Force -Path $BinPath | Out-Null
}
& (Join-Path $RootPath "scripts\generate-winres.ps1") -RootPath $RootPath
# 提取版本信息
$tag = git describe --tags --always --dirty 2>$null
if (-not $tag) { $tag = "dev" }
$time = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$ldflags = "-H=windowsgui -s -w -X 'main.version=$tag' -X 'main.buildTime=$time'"
Write-Host ">>> Compiling Go backend ($tag)..." -ForegroundColor Cyan
go build -ldflags $ldflags -trimpath -o $ExePath ./cmd/server
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed!" -ForegroundColor Red
exit 1
}
Write-Host "Build success: $ExePath" -ForegroundColor Green
}
function Sign {
if (-not (Test-Path $ExePath)) {
Write-Host "Error: Cannot find $ExePath, build first." -ForegroundColor Red
exit 1
}
if (-not (Test-Path $CertPath)) {
Write-Host "Skip signing: Certificate not found ($CertPath)" -ForegroundColor Yellow
return
}
$signtool = Get-SignTool
if (-not $signtool) {
Write-Host "Warning: signtool.exe not found, skipping sign" -ForegroundColor Yellow
return
}
$pass = Get-Content $CertPassPath -Raw
$pass = $pass.Trim()
Write-Host ">>> Signing $ExePath..." -ForegroundColor Cyan
& $signtool sign /fd sha256 /f $CertPath /p $pass $ExePath
if ($LASTEXITCODE -eq 0) {
Write-Host "Sign success!" -ForegroundColor Green
} else {
Write-Host "Sign failed, code: $LASTEXITCODE" -ForegroundColor Red
}
}
switch ($Action) {
"build" {
Build
}
"sign" {
Sign
}
"all" {
Build
Sign
}
"clean" {
if (Test-Path $BinPath) {
Remove-Item -Recurse -Force $BinPath
Write-Host "Cleaned $BinPath" -ForegroundColor Green
}
}
default {
Write-Host "Unknown action: $Action. Available actions: build, sign, all, clean" -ForegroundColor Red
}
}