Files
dsh-markmag/scripts/bootstrap.sh
T

81 lines
3.4 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.
#!/usr/bin/env bash
# 员工一键接入(2026-11-12 v2:取码换 key 改纯 bash+curl,不再依赖 node——
# 员工机普遍没有全局 node,DSH 桌面端只自带运行时,v1 在此翻车实锤)。
#
# 跑法(员工唯一要记的一条;bash <(...) 保住终端输入,取码时还要粘码):
# bash <(curl -fsSL https://brain.sidaocai.cn/git/sidaocai/dsh-markmag/raw/branch/main/scripts/bootstrap.sh)
#
# 可选环境变量:DSH_CLI(CLI 路径)、PROFILE(默认 desktop)、DSH_REPO(自建源)、MARKMAG
set -euo pipefail
DSH_CLI="${DSH_CLI:-/Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh}"
PROFILE="${1:-${PROFILE:-desktop}}"
DSH_REPO="${DSH_REPO:-https://brain.sidaocai.cn/git/sidaocai/dsh-markmag.git}"
MARKMAG="${MARKMAG:-https://brain.sidaocai.cn/markmag}"
CRED="$HOME/.dsh/.credentials.yaml"
if [ ! -x "$DSH_CLI" ]; then
echo "✗ 没找到 DSH 命令行($DSH_CLI)。先装 DeepSeek Harness 桌面端,或用 DSH_CLI= 指路径。"
exit 1
fi
echo "[1/2] 安装弹匣插件 → profile: $PROFILE"
"$DSH_CLI" plugin --profile "$PROFILE" add "$DSH_REPO"
echo "[2/2] 取码换 key"
echo "浏览器马上会弹出取码页(没登录就先钉钉扫码,登完重新打开一次)"
open "$MARKMAG/api/dsh/link" 2>/dev/null || echo "请手动打开:$MARKMAG/api/dsh/link"
printf '把页面上的 8 位码粘进来(粘完按回车):'
read -r CODE
CODE="$(printf '%s' "$CODE" | tr -d '[:space:]' | tr '[:lower:]' '[:upper:]')"
if ! [[ "$CODE" =~ ^[A-Z0-9]{8}$ ]]; then
echo "✗ 码格式不对(应该 8 位字母数字)"
exit 1
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)"
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)"
if [ -z "$KEY" ]; then
echo "✗ 返回的 key 形状不对,拒绝写入"
exit 1
fi
if [ ! -f "$CRED" ]; then
mkdir -p "$HOME/.dsh"
printf 'refs:\n' > "$CRED"
chmod 600 "$CRED"
fi
cp "$CRED" "$CRED.bak-$(date +%s)"
set_cred() { # 名 值 —— 已有则替换;没有则插到 refs: 下(无 refs: 则补一节)
if grep -q "^[[:space:]]*$1:" "$CRED"; then
sed -i '' "s|^[[:space:]]*$1:.*| $1: $2|" "$CRED"
elif grep -q '^refs:' "$CRED"; then
awk -v kv=" $1: $2" '/^refs:/ && !d { print; print kv; d=1; next } { print }' \
"$CRED" > "$CRED.tmp" && mv "$CRED.tmp" "$CRED"
else
printf 'refs:\n %s: %s\n' "$1" "$2" >> "$CRED"
fi
}
set_cred MARKMAG_TEAM_KEY "$KEY"
if [ -n "$TOOL" ]; then set_cred MARKMAG_TOOL_TOKEN "$TOOL"; fi
if grep -q 'MARKMAG_TEAM_KEY: sk-mem-' "$CRED"; then
echo ""
echo "✓ 完成:key 已写进 DSH 凭据"
echo "现在重启 DeepSeek Harness → 模型选「四道菜 · GLM-5.3-Flash」→ 开聊。"
echo "以后不用再做这一步了。"
else
echo "✗ 写入后自检失败(截图这段找发条)"
exit 1
fi