支持跨平台部署镜像工具

This commit is contained in:
chenxi 2026-09-26 03:42:25 +08:00
parent 9e89fe3bf2
commit 6a9bee82e9

View File

@ -200,11 +200,33 @@ function Compress-Gzip {
function Get-RegctlPath { function Get-RegctlPath {
$toolRoot = Join-Path $env:LOCALAPPDATA 'CaiWuXiTong\tools' $toolRoot = Join-Path $env:LOCALAPPDATA 'CaiWuXiTong\tools'
$regctlPath = Join-Path $toolRoot "regctl-$regctlVersion.exe" $regctlAsset = 'regctl-windows-amd64.exe'
$regctlExtension = '.exe'
$expectedHash = $regctlSha256
if ($IsMacOS -and [Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq [Runtime.InteropServices.Architecture]::Arm64) {
$regctlAsset = 'regctl-darwin-arm64'
$regctlExtension = ''
$expectedHash = 'f4d536d64d0c3cc1db7400902175a1c314675991d22e87e15c319501a2676d3f'
}
elseif ($IsMacOS) {
$regctlAsset = 'regctl-darwin-amd64'
$regctlExtension = ''
$expectedHash = 'c132fdddda68b9c7584ac19f3b40cd17f71916c2bca8182270ebe65b55198a12'
}
elseif ($IsLinux -and [Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq [Runtime.InteropServices.Architecture]::Arm64) {
$regctlAsset = 'regctl-linux-arm64'
$regctlExtension = ''
$expectedHash = 'c4cf231e74cda685f1599f3d866b02b03c572e54b79ec8b062f32070b0ba4587'
}
elseif ($IsLinux) {
$regctlAsset = 'regctl-linux-amd64'
$regctlExtension = ''
}
$regctlPath = Join-Path $toolRoot "regctl-$regctlVersion$regctlExtension"
if (Test-Path -LiteralPath $regctlPath) { if (Test-Path -LiteralPath $regctlPath) {
$actualHash = (Get-FileHash -LiteralPath $regctlPath -Algorithm SHA256).Hash.ToLowerInvariant() $actualHash = (Get-FileHash -LiteralPath $regctlPath -Algorithm SHA256).Hash.ToLowerInvariant()
if ($actualHash -eq $regctlSha256) { if ($actualHash -eq $expectedHash) {
return $regctlPath return $regctlPath
} }
Remove-Item -LiteralPath $regctlPath -Force Remove-Item -LiteralPath $regctlPath -Force
@ -214,11 +236,11 @@ function Get-RegctlPath {
$downloadPath = "$regctlPath.download" $downloadPath = "$regctlPath.download"
try { try {
Invoke-WebRequest ` Invoke-WebRequest `
-Uri "https://github.com/regclient/regclient/releases/download/$regctlVersion/regctl-windows-amd64.exe" ` -Uri "https://github.com/regclient/regclient/releases/download/$regctlVersion/$regctlAsset" `
-OutFile $downloadPath -OutFile $downloadPath
$actualHash = (Get-FileHash -LiteralPath $downloadPath -Algorithm SHA256).Hash.ToLowerInvariant() $actualHash = (Get-FileHash -LiteralPath $downloadPath -Algorithm SHA256).Hash.ToLowerInvariant()
if ($actualHash -ne $regctlSha256) { if ($actualHash -ne $expectedHash) {
throw "regctl 校验失败:预期 $regctlSha256,实际 $actualHash。" throw "regctl 校验失败:预期 $expectedHash,实际 $actualHash。"
} }
Move-Item -LiteralPath $downloadPath -Destination $regctlPath -Force Move-Item -LiteralPath $downloadPath -Destination $regctlPath -Force
} }