Files
LTEDongle/flasher/package-release.ps1
T
nixevol d951535e30 feat: 面板加入网页终端,并自带离线依赖
只更新面板、不重刷系统时,终端和热点仍能用包里的 ttyd 与 hostapd。
2026-11-30 18:07:35 +08:00

160 lines
6.4 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 把已经编译好的 MiFiPanel 收进 flasher\panel,并打成 flasher\dist\panel.zip。
# 本脚本不编译。缺文件就说明原因并退出。
#
# 加上 -Release <目录> 时,再把整套刷机工具(程序、运行环境、型号资料和镜像、驱动、面板)
# 同步到这个目录,得到一份拷到别的电脑就能用的刷机工具。例如:
# .\package-release.ps1 -Release ..\dist\UFI003_MB_V02_Flasher
param([string]$Release = '')
$ErrorActionPreference = 'Stop'
$flasher = $PSScriptRoot
if ([string]::IsNullOrWhiteSpace($flasher)) {
$flasher = Split-Path -Parent $MyInvocation.MyCommand.Path
}
$repo = Split-Path -Parent $flasher
$source = Join-Path $repo 'mifipanel'
$binary = Join-Path $source 'target\aarch64-unknown-linux-gnu\release\mifipanel'
$web = Join-Path $source 'web'
$service = Join-Path $source 'mifipanel.service'
$radio = Join-Path $source 'radio-schemes.json'
$imei = Join-Path $source 'imei-schemes.json'
$offline = Join-Path $source 'offline'
$ttyd = Join-Path $offline 'ttyd'
$panel = Join-Path $flasher 'panel'
$dist = Join-Path $flasher 'dist'
$zip = Join-Path $dist 'panel.zip'
$missing = @()
if (-not (Test-Path -LiteralPath $binary -PathType Leaf)) {
$missing += "缺少已编译的 aarch64 程序:$binary"
}
if (-not (Test-Path -LiteralPath $web -PathType Container)) {
$missing += "缺少页面目录:$web"
}
if (-not (Test-Path -LiteralPath $service -PathType Leaf)) {
$missing += "缺少服务文件:$service"
}
if (-not (Test-Path -LiteralPath $radio -PathType Leaf)) {
$missing += "缺少 radio-schemes.json:$radio"
}
if (-not (Test-Path -LiteralPath $imei -PathType Leaf)) {
$missing += "缺少 imei-schemes.json:$imei"
}
if (-not (Test-Path -LiteralPath $offline -PathType Container)) {
$missing += "缺少 offline 目录:$offline"
}
$debs = @()
if (Test-Path -LiteralPath $offline -PathType Container) {
$debs = @(Get-ChildItem -LiteralPath $offline -File -Filter 'hostapd*.deb' | Sort-Object Name)
if ($debs.Count -eq 0) {
$missing += "缺少 hostapd 的 deb:$offline\hostapd*.deb"
}
}
if (-not (Test-Path -LiteralPath $ttyd -PathType Leaf)) {
$missing += "缺少网页终端程序:$ttyd"
}
if ($missing.Count -gt 0) {
[Console]::Error.WriteLine('打包失败。本脚本不会交叉编译,请先备好下面这些文件。')
foreach ($item in $missing) {
[Console]::Error.WriteLine($item)
}
exit 1
}
if (Test-Path -LiteralPath $panel) {
Remove-Item -LiteralPath $panel -Recurse -Force
}
New-Item -ItemType Directory -Path (Join-Path $panel 'offline') -Force | Out-Null
if (-not (Test-Path -LiteralPath $dist -PathType Container)) {
New-Item -ItemType Directory -Path $dist | Out-Null
}
$offlineDir = Join-Path $panel 'offline'
Copy-Item -LiteralPath $binary -Destination (Join-Path $panel 'mifipanel') -Force
Copy-Item -LiteralPath $web -Destination (Join-Path $panel 'web') -Recurse -Force
Copy-Item -LiteralPath $service -Destination (Join-Path $panel 'mifipanel.service') -Force
Copy-Item -LiteralPath $radio -Destination (Join-Path $panel 'radio-schemes.json') -Force
Copy-Item -LiteralPath $imei -Destination (Join-Path $panel 'imei-schemes.json') -Force
foreach ($deb in $debs) {
Copy-Item -LiteralPath $deb.FullName -Destination (Join-Path $offlineDir $deb.Name) -Force
}
Copy-Item -LiteralPath $ttyd -Destination (Join-Path $offlineDir 'ttyd') -Force
Copy-Item -LiteralPath $ttyd -Destination (Join-Path $panel 'ttyd') -Force
$license = Join-Path $offline 'LICENSE-ttyd'
if (Test-Path -LiteralPath $license -PathType Leaf) {
Copy-Item -LiteralPath $license -Destination (Join-Path $offlineDir 'LICENSE-ttyd') -Force
}
$stagedBin = Join-Path $panel 'mifipanel'
$stagedWeb = Join-Path $panel 'web'
$stagedService = Join-Path $panel 'mifipanel.service'
if (-not (Test-Path -LiteralPath $stagedBin -PathType Leaf)) {
[Console]::Error.WriteLine("复制程序失败:$stagedBin")
exit 1
}
if (-not (Test-Path -LiteralPath $stagedWeb -PathType Container)) {
[Console]::Error.WriteLine("复制页面失败:$stagedWeb")
exit 1
}
if (-not (Test-Path -LiteralPath $stagedService -PathType Leaf)) {
[Console]::Error.WriteLine("复制服务文件失败:$stagedService")
exit 1
}
if (Test-Path -LiteralPath $zip) {
Remove-Item -LiteralPath $zip -Force
}
Compress-Archive -Path $panel -DestinationPath $zip -CompressionLevel Optimal
if (-not (Test-Path -LiteralPath $zip -PathType Leaf)) {
[Console]::Error.WriteLine("没有生成压缩包:$zip")
exit 1
}
Write-Output "已打包:$zip"
if (-not [string]::IsNullOrWhiteSpace($Release)) {
$exe = Join-Path $flasher 'target\release\flasher.exe'
if (-not (Test-Path -LiteralPath $exe -PathType Leaf)) {
[Console]::Error.WriteLine("缺少已编译的刷机工具:$exe。请先在 flasher 目录执行 cargo build --release。")
exit 1
}
if (-not (Test-Path -LiteralPath $Release -PathType Container)) {
New-Item -ItemType Directory -Path $Release -Force | Out-Null
}
$target = (Resolve-Path -LiteralPath $Release).Path
# 备份目录是每台设备自己的校准数据,不跟着发布走;改镜像时留下的旧镜像也不带。
$jobs = @(
@{ Name = 'runtime'; Skip = @('/XD', '__pycache__', 'logs') },
# selected.txt 记着上次在界面里选的型号,属于使用的人,不覆盖也不删。
@{ Name = 'devices'; Skip = @('/XF', '*.before-*', 'selected.txt') },
@{ Name = 'drivers'; Skip = @() },
@{ Name = 'panel'; Skip = @() }
)
foreach ($job in $jobs) {
$from = Join-Path $flasher $job.Name
if (-not (Test-Path -LiteralPath $from -PathType Container)) {
[Console]::Error.WriteLine("缺少目录:$from")
exit 1
}
$to = Join-Path $target $job.Name
& robocopy $from $to /MIR /R:1 /W:1 /NFL /NDL /NJH /NJS /NP @($job.Skip) | Out-Null
if ($LASTEXITCODE -ge 8) {
[Console]::Error.WriteLine("同步 $($job.Name) 失败")
exit 1
}
}
try {
Copy-Item -LiteralPath $exe -Destination (Join-Path $target 'flasher.exe') -Force
Write-Output "已同步刷机工具:$target"
} catch {
# 目录里的 flasher.exe 正开着时换不掉。其它文件已经是新的。
[Console]::Error.WriteLine("其它文件已同步,但 flasher.exe 正在运行,没能替换。请关掉刷机工具后再执行一次。")
exit 2
}
}
exit 0