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

86 lines
3.6 KiB
Bash
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.

#!/bin/bash
# 为 Uptime Kuma 的 Bark 通知启用:自定义图标 / 消息分组 / 重要警告 / 图片推送 / 角标
# 2026-09-13
# 前置:以下文件需先 scp 到 /tmp单个文件逐个传多文件 scp 会静默丢文件)
# /tmp/bark-icon.png /tmp/bark-down.png /tmp/bark-up.png
# /tmp/bark.js /tmp/status.xpcool.com.conf
# 幂等:可重复执行
ASSET_DIR=/data/www/bark-assets
PATCH_DIR=/data/uptime-kuma-patch
IMAGE=louislam/uptime-kuma:2.5.3
TS=$(date +%Y%m%d%H%M%S)
echo "=== 0. 备份当前容器配置与 nginx 配置(便于回滚) ==="
sudo docker inspect uptime-kuma > "/tmp/kuma-inspect.$TS.json"
echo "inspect 已存 /tmp/kuma-inspect.$TS.json"
sudo docker inspect uptime-kuma --format 'restart={{json .HostConfig.RestartPolicy}} mem={{.HostConfig.Memory}}B port={{json .HostConfig.PortBindings}} env={{json .Config.Env}}'
sudo cp -a /data/nginx/conf.d/status.xpcool.com.conf "/data/nginx/conf.d/status.xpcool.com.conf.bak.$TS"
echo ""
echo "=== 1. 部署 Bark 素材 ==="
sudo mkdir -p "$ASSET_DIR" "$PATCH_DIR"
for f in icon down up; do
if [ -f "/tmp/bark-$f.png" ]; then
sudo mv -f "/tmp/bark-$f.png" "$ASSET_DIR/$f.png"
fi
done
sudo chmod 644 "$ASSET_DIR"/*.png
sudo chmod 755 "$ASSET_DIR"
ls -l "$ASSET_DIR"
echo ""
echo "=== 2. 安装 provider 补丁 ==="
if [ -f /tmp/bark.js ]; then
sudo mv -f /tmp/bark.js "$PATCH_DIR/bark.js"
fi
sudo chmod 644 "$PATCH_DIR/bark.js"
sudo cp -f "$PATCH_DIR/bark.js" /tmp/_bark_check.js
sudo docker cp /tmp/_bark_check.js uptime-kuma:/tmp/_bark_check.js > /dev/null
sudo docker exec uptime-kuma node --check /tmp/_bark_check.js && echo "补丁语法检查 OK"
sudo docker exec uptime-kuma rm -f /tmp/_bark_check.js
rm -f /tmp/_bark_check.js
echo "补丁 md5$(md5sum "$PATCH_DIR/bark.js" | cut -d' ' -f1)"
echo ""
echo "=== 3. 部署 nginx 配置(新增 /bark-assets/ 静态位置) ==="
if [ -f /tmp/status.xpcool.com.conf ]; then
sudo mv -f /tmp/status.xpcool.com.conf /data/nginx/conf.d/status.xpcool.com.conf
fi
sudo nginx -t
sudo systemctl reload nginx
echo "nginx reload OK"
echo ""
echo "=== 4. 公网取图验证(手机端要能直接拉到) ==="
for f in icon down up; do
curl -s -o /dev/null -m 15 -w "$f.png code=%{http_code} type=%{content_type} size=%{size_download}\n" \
"https://status.xpcool.com/bark-assets/$f.png"
done
echo ""
echo "=== 5. 重建容器以挂载补丁(数据卷 /data/uptime-kuma 不变) ==="
sudo docker rm -f uptime-kuma > /dev/null 2>&1
sudo docker run -d --name uptime-kuma --restart unless-stopped \
-p 127.0.0.1:3001:3001 \
-e TZ=Asia/Shanghai \
-v /data/uptime-kuma:/app/data \
-v /data/uptime-kuma-patch/bark.js:/app/server/notification-providers/bark.js:ro \
--memory 512m \
"$IMAGE" > /dev/null
sleep 20
sudo docker ps --filter name=uptime-kuma --format '{{.Names}} | {{.Status}} | {{.Ports}}'
echo ""
echo "=== 6. 确认补丁确实生效 ==="
echo -n "宿主机补丁 md5 : "; md5sum "$PATCH_DIR/bark.js" | cut -d' ' -f1
echo -n "容器内文件 md5 : "; sudo docker exec uptime-kuma md5sum /app/server/notification-providers/bark.js 2>&1 | cut -d' ' -f1
echo -n "定制标记行数 : "; sudo docker exec uptime-kuma grep -c "xpcool 定制" /app/server/notification-providers/bark.js 2>&1
echo -n "图标常量 : "; sudo docker exec uptime-kuma grep -m1 "barkNotificationAvatar =" /app/server/notification-providers/bark.js 2>&1
echo ""
echo "=== 7. 面板可用性 ==="
curl -s -o /dev/null -m 10 -w "panel=%{http_code}\n" http://127.0.0.1:3001/
sudo docker exec uptime-kuma sqlite3 /app/data/kuma.db "SELECT id,name,active,json_extract(config,'\$.type') FROM notification;"
echo "DONE"