bootstrap v3:JSON提取改grep -o(BSD sed 无或运算,v2 在 macOS 把成功误判为失败——海英机实锤)
This commit is contained in:
1 parent
3c6a83d300
commit
df7ce6854b
1 file changed
+5
-5
@@ -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
|
||||
|
||||
Reference in new issue
Block a user