fix(ops): seo-unblock v3 补——博客主站判定字符类修正

v2 残留:([[:space:]];|$) 被解析为空格+分号序列而非字符类,-x 兜底
吃行首缩进——admin location 两轮未落。统一 (^|[[:space:];]) 词边界
并显式排除 git 子域。

验证: bash -n 过;判定正则对 /etc/nginx/sites-enabled/default 实文件
干跑(博客行命中/git 行排除双验)

Spec: none (脚本热修 v3 补)

Co-authored-by: GLM-5.3
This commit is contained in:
wait4xandGLM-5.3 committed 2026-11-01 11:16:21 +08:00
1 parent ca7d71325c
commit 3b65cc47ec
1 file changed
+4 -4
+4 -4
View File
@@ -20,11 +20,11 @@ for f in "$SITES"/*; do
names=$(sudo grep -h "server_name" "$f" 2>/dev/null || true)
[ -z "$names" ] && continue
# 内部服务判定:server_name 含内部子域且不含主站裸域
if sudo grep -q "include snippets/esa-origin-ssl" "$f" && ! echo "$names" | grep -qE "server_name[^;]*(^|[[:space:]])(www\.)?wait4x\.online([[:space:]];|$)" || echo "$names" | grep -qx "server_name wait4x.online;"; then
if sudo grep -q "include snippets/esa-origin-ssl" "$f" && ! echo "$names" | grep -qE "(^|[[:space:];])(www\.)?wait4x\.online([[:space:];]|$)" && ! echo "$names" | grep -qE "(^|[[:space:]])git\.wait4x\.online"; then
sudo grep -q "X-Robots-Tag" "$f" || echo " [补回] $f:server 块加 add_header X-Robots-Tag noindex always;"
fi
# 博客主站判定:server_name 恰含裸域
if echo "$names" | grep -qE "server_name[^;]*(^|[[:space:]])(www\.)?wait4x\.online([[:space:]];|$)" || echo "$names" | grep -qx "server_name wait4x.online;"; then
if echo "$names" | grep -qE "(^|[[:space:];])(www\.)?wait4x\.online([[:space:];]|$)" && ! echo "$names" | grep -qE "(^|[[:space:]])git\.wait4x\.online"; then
sudo grep -q "location /admin/" "$f" || echo " [新增] $f:location /admin/ { noindex }"
fi
done
@@ -41,7 +41,7 @@ sudo sed -i '/X-Robots-Tag noindex/d' "$SNIPPET" && echo " snippet 已剥 noind
for f in "$SITES"/*; do
names=$(sudo grep -h "server_name" "$f" 2>/dev/null || true)
[ -z "$names" ] && continue
if sudo grep -q "include snippets/esa-origin-ssl" "$f" && ! echo "$names" | grep -qE "server_name[^;]*(^|[[:space:]])(www\.)?wait4x\.online([[:space:]];|$)" || echo "$names" | grep -qx "server_name wait4x.online;"; then
if sudo grep -q "include snippets/esa-origin-ssl" "$f" && ! echo "$names" | grep -qE "(^|[[:space:];])(www\.)?wait4x\.online([[:space:];]|$)" && ! echo "$names" | grep -qE "(^|[[:space:]])git\.wait4x\.online"; then
if ! sudo grep -q "X-Robots-Tag" "$f"; then
sudo cp "$f" "$BAKDIR/$(basename "$f")"
# 在首个 server_name 行后插入(server 块内、顶层指令位置合法)
@@ -49,7 +49,7 @@ for f in "$SITES"/*; do
echo " 补回:$f"
fi
fi
if echo "$names" | grep -qE "server_name[^;]*(^|[[:space:]])(www\.)?wait4x\.online([[:space:]];|$)" || echo "$names" | grep -qx "server_name wait4x.online;"; then
if echo "$names" | grep -qE "(^|[[:space:];])(www\.)?wait4x\.online([[:space:];]|$)" && ! echo "$names" | grep -qE "(^|[[:space:]])git\.wait4x\.online"; then
if ! sudo grep -q "location /admin/" "$f"; then
sudo cp "$f" "$BAKDIR/$(basename "$f")"
sudo sed -i "0,/server_name/s/\(server_name.*\)/\1\n location \/admin\/ { add_header X-Robots-Tag noindex always; }/" "$f"