From df7ce6854b5ca0fb372e646f427e4e7d87e2b0bd Mon Sep 17 00:00:00 2001 From: zzxsmile <523954578@qq.com> Date: Thu, 12 Nov 2026 16:04:54 +0800 Subject: [PATCH] =?UTF-8?q?bootstrap=20v3=EF=BC=9AJSON=E6=8F=90=E5=8F=96?= =?UTF-8?q?=E6=94=B9grep=20-o=EF=BC=88BSD=20sed=20=E6=97=A0=E6=88=96?= =?UTF-8?q?=E8=BF=90=E7=AE=97=EF=BC=8Cv2=20=E5=9C=A8=20macOS=20=E6=8A=8A?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E8=AF=AF=E5=88=A4=E4=B8=BA=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E2=80=94=E2=80=94=E6=B5=B7=E8=8B=B1=E6=9C=BA=E5=AE=9E=E9=94=A4?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/bootstrap.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 190633b..ef75530 100644 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -36,14 +36,14 @@ fi RES="$(curl -fsS --max-time 20 -X POST "$MARKMAG/api/dsh/link-exchange" \ -H 'content-type: application/json' -d "{\"code\":\"$CODE\"}" 2>/dev/null \ || echo '{"ok":false,"err":"连不上弹匣(看下网络或稍后再试)"}')" -OK="$(printf '%s' "$RES" | sed -n 's/.*"ok":\(true\|false\).*/\1/p' | head -1)" -if [ "$OK" != "true" ]; then - ERR="$(printf '%s' "$RES" | sed -n 's/.*"err":"\([^"]*\)".*/\1/p' | head -1)" +# 解析一律 grep -o(BSD/GNU 通用;勿用 sed \(a\|b\) —— BSD sed 无或运算,v2 在此误判成功为失败) +if ! printf '%s' "$RES" | grep -q '"ok": *true'; then + ERR="$(printf '%s' "$RES" | grep -o '"err": *"[^"]*"' | head -1 | sed 's/"err": *"//;s/"$//')" echo "✗ ${ERR:-换 key 失败}(码 5 分钟过期;重新打开取码页取一个新的,再重跑本命令)" exit 1 fi -KEY="$(printf '%s' "$RES" | sed -n 's/.*"user_key":"\(sk-mem-[^"]*\)".*/\1/p' | head -1)" -TOOL="$(printf '%s' "$RES" | sed -n 's/.*"tool_token":"\([^"]*\)".*/\1/p' | head -1)" +KEY="$(printf '%s' "$RES" | grep -o 'sk-mem-[A-Za-z0-9_-]*' | head -1)" +TOOL="$(printf '%s' "$RES" | grep -o '"tool_token": *"[^"]*"' | head -1 | sed 's/"tool_token": *"//;s/"$//')" if [ -z "$KEY" ]; then echo "✗ 返回的 key 形状不对,拒绝写入" exit 1