From 7141d1f2d11b3f9c614d74deea11f44138e84675 Mon Sep 17 00:00:00 2001 From: hotyue <52734432+hotyue@users.noreply.github.com> Date: Wed, 1 Apr 2026 06:48:22 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=96=E5=86=99=E5=B8=A6=E6=9C=89?= =?UTF-8?q?=E5=AE=B9=E7=81=BE=E6=9C=BA=E5=88=B6=E7=9A=84=20OTA=20=E9=9D=99?= =?UTF-8?q?=E9=BB=98=E5=85=BB=E6=96=99=E6=9B=B4=E6=96=B0=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/updater.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/core/updater.sh b/core/updater.sh index e69de29..d14f0c9 100644 --- a/core/updater.sh +++ b/core/updater.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# ========================================================== +# 脚本名称: updater.sh (IP-Sentinel 养料注入模块) +# 核心功能: 定期静默从云端拉取最新的搜索词库与 UA 指纹池 (OTA更新) +# ========================================================== + +INSTALL_DIR="/opt/ip_sentinel" +CONFIG_FILE="${INSTALL_DIR}/config.conf" +# 你的专属 Forgejo 仓库 Raw 数据直链前缀 +REPO_RAW_URL="https://git.94211762.xyz/hotyue/IP-Sentinel/raw/branch/main" + +# 1. 加载本地冷数据配置 +if [ ! -f "$CONFIG_FILE" ]; then + exit 1 +fi +source "$CONFIG_FILE" + +# 2. 全局日志写入函数 (兼容统一格式) +log() { + mkdir -p "${INSTALL_DIR}/logs" + printf "[$(date '+%Y-%m-%d %H:%M:%S')] [%-5s] [%-7s] [%s] %s\n" "$2" "$1" "$REGION_CODE" "$3" >> "$LOG_FILE" +} + +log "Updater" "INFO " "========== 触发后台静默 OTA 热数据更新 ==========" + +# 3. 容灾机制拉取 UA 池 (下载到临时文件,如果成功且不为空,再覆盖原文件) +TMP_UA="/tmp/ip_sentinel_ua.txt" +curl -sL "${REPO_RAW_URL}/data/user_agents.txt" -o "$TMP_UA" +if [ -s "$TMP_UA" ]; then + mv "$TMP_UA" "${INSTALL_DIR}/data/user_agents.txt" + log "Updater" "INFO " "✅ 设备指纹池 (User-Agents) 更新成功" +else + log "Updater" "WARN " "❌ UA 池拉取失败或为空,保留本地旧数据防崩溃" + rm -f "$TMP_UA" +fi + +# 4. 容灾机制拉取当地最新搜索词库 +TMP_KW="/tmp/ip_sentinel_kw.txt" +curl -sL "${REPO_RAW_URL}/data/keywords/kw_${REGION_CODE}.txt" -o "$TMP_KW" +if [ -s "$TMP_KW" ]; then + mv "$TMP_KW" "${INSTALL_DIR}/data/keywords/kw_${REGION_CODE}.txt" + log "Updater" "INFO " "✅ 区域搜索词库 (kw_${REGION_CODE}) 更新成功" +else + log "Updater" "WARN " "❌ 搜索词库拉取失败,保留本地旧数据防崩溃" + rm -f "$TMP_KW" +fi + +log "Updater" "INFO " "========== OTA 养料注入流程结束 ==========" \ No newline at end of file