workbuddy.xpcool.com/.workbuddy/tmp/deploy-bark-custom.ps1

73 lines
3.2 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.

# =====================================================================
# 一键部署Uptime Kuma 的 Bark 通知增强
# 自定义推送图标 / 消息分组 / 重要警告 / 图片推送 / 角标
# 2026-09-13
#
# 用法(在本机 PowerShell 里执行):
# powershell -ExecutionPolicy Bypass -File "E:\Project\workbuddy.xpcool.com\.workbuddy\tmp\deploy-bark-custom.ps1"
#
# 执行完会把全过程日志写到 logs\bark-deploy-<时间戳>.log把它发我即可。
# =====================================================================
$ErrorActionPreference = "Continue"
$T = "E:\Project\workbuddy.xpcool.com\.workbuddy\tmp"
$scp = "$env:SystemRoot\System32\OpenSSH\scp.exe"
$ssh = "$env:SystemRoot\System32\OpenSSH\ssh.exe"
$key = "$env:USERPROFILE\.ssh\xpcool_ed25519"
$host_ = "xxcool@193.112.118.168"
$port = "22025"
$logDir = Join-Path $T "logs"
New-Item -ItemType Directory -Path $logDir -Force | Out-Null
$logFile = Join-Path $logDir ("bark-deploy-{0}.log" -f (Get-Date -Format "yyyyMMdd-HHmmss"))
$log = New-Object System.Collections.Generic.List[string]
function Say($text) {
Write-Host $text
$log.Add($text)
}
Say "===== Bark 通知增强部署 $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') ====="
# --- 1. 上传(单个文件逐个传:多文件 scp 会静默丢文件) ---
$pairs = @(
@("$T\bark-assets\icon.png", "/tmp/bark-icon.png"),
@("$T\bark-assets\down.png", "/tmp/bark-down.png"),
@("$T\bark-assets\up.png", "/tmp/bark-up.png"),
@("$T\bark.js", "/tmp/bark.js"),
@("$T\status.xpcool.com.conf", "/tmp/status.xpcool.com.conf"),
@("$T\deploy-bark-custom.sh", "/tmp/deploy-bark-custom.sh"),
@("$T\kuma-bark-verify.sh", "/tmp/kuma-bark-verify.sh")
)
Say ""
Say "--- 1. 上传文件 ---"
foreach ($p in $pairs) {
$leaf = Split-Path $p[0] -Leaf
if (-not (Test-Path $p[0])) { Say ("!! 本地缺少 {0},跳过" -f $leaf); continue }
$out = & $scp -o BatchMode=yes -o StrictHostKeyChecking=no -i $key -P $port $p[0] "$host_:$($p[1])" 2>&1
Say ("scp {0} -> exit={1} {2}" -f $leaf, $LASTEXITCODE, ($out -join " "))
}
$out = & $ssh -o BatchMode=yes -o StrictHostKeyChecking=no -i $key -p $port $host_ "ls -l /tmp/bark-*.png /tmp/bark.js /tmp/status.xpcool.com.conf /tmp/deploy-bark-custom.sh /tmp/kuma-bark-verify.sh" 2>&1
Say ($out -join "`n")
# --- 2. 执行部署 ---
Say ""
Say "--- 2. 部署(素材 + provider 补丁 + nginx + 重建容器) ---"
$out = & $ssh -o BatchMode=yes -o StrictHostKeyChecking=no -i $key -p $port $host_ "chmod +x /tmp/deploy-bark-custom.sh && /tmp/deploy-bark-custom.sh" 2>&1
Say ($out -join "`n")
# --- 3. 端到端验证(临时监控触发真实 DOWN验证后自动清理 ---
Say ""
Say "--- 3. 端到端验证(会往你手机推一条真实的 Down 告警) ---"
$out = & $ssh -o BatchMode=yes -o StrictHostKeyChecking=no -i $key -p $port $host_ "chmod +x /tmp/kuma-bark-verify.sh && /tmp/kuma-bark-verify.sh" 2>&1
Say ($out -join "`n")
Say ""
Say "===== 结束,日志:$logFile ====="
$log -join "`r`n" | Out-File -FilePath $logFile -Encoding utf8
Write-Host ""
Write-Host ("日志已保存:" + $logFile) -ForegroundColor Green