52 lines
1.5 KiB
PowerShell
52 lines
1.5 KiB
PowerShell
|
|
<#
|
|||
|
|
.SYNOPSIS
|
|||
|
|
生成 integrity.sha256 文件
|
|||
|
|
.DESCRIPTION
|
|||
|
|
计算 hooks 和关键配置文件的 SHA256 哈希,
|
|||
|
|
写入 integrity.sha256 供 install.ps1 校验.
|
|||
|
|
每次 prepare-repo.ps1 推送前应运行此脚本.
|
|||
|
|
.USAGE
|
|||
|
|
.\generate-integrity.ps1
|
|||
|
|
#>
|
|||
|
|
|
|||
|
|
$ClaudeDir = Join-Path $env:USERPROFILE ".claude"
|
|||
|
|
$OutputFile = Join-Path $ClaudeDir "integrity.sha256"
|
|||
|
|
|
|||
|
|
if (-not (Test-Path $ClaudeDir)) {
|
|||
|
|
Write-Host "[ERROR] .claude 目录不存在" -ForegroundColor Red
|
|||
|
|
exit 1
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Write-Host " 生成 integrity.sha256..." -ForegroundColor Cyan
|
|||
|
|
|
|||
|
|
# 需要校验的关键文件模式
|
|||
|
|
$patterns = @(
|
|||
|
|
"hooks/*.js",
|
|||
|
|
"hooks/lib/*.js",
|
|||
|
|
"scripts/paths.config.js",
|
|||
|
|
"CLAUDE.md",
|
|||
|
|
"settings.template.json",
|
|||
|
|
"settings.local.template.json"
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
$hashes = @()
|
|||
|
|
foreach ($pattern in $patterns) {
|
|||
|
|
$fullPattern = Join-Path $ClaudeDir $pattern
|
|||
|
|
foreach ($file in (Get-Item $fullPattern -ErrorAction SilentlyContinue)) {
|
|||
|
|
$hash = (Get-FileHash $file.FullName -Algorithm SHA256).Hash.ToLower()
|
|||
|
|
$relPath = $file.FullName.Substring($ClaudeDir.Length + 1).Replace('\', '/')
|
|||
|
|
$hashes += "$hash $relPath"
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 去重并排序
|
|||
|
|
$hashes = $hashes | Sort-Object -Unique
|
|||
|
|
|
|||
|
|
$hashes | Set-Content $OutputFile -Encoding UTF8
|
|||
|
|
$count = $hashes.Count
|
|||
|
|
|
|||
|
|
Write-Host " [OK] 已生成 $count 个文件哈希" -ForegroundColor Green
|
|||
|
|
Write-Host " 路径: $OutputFile" -ForegroundColor Gray
|
|||
|
|
Write-Host ""
|
|||
|
|
Write-Host " 注意: 请在 git commit 前运行此脚本" -ForegroundColor Yellow
|