03d9782f22
leo 問「寫以前為什麼不查」——沒有藉口,我假設了兩件事都沒查,兩件都是錯的。 ① setup script 讀不到 Environment variables 官方原文:Each session copies the environment's values once, at startup, into ordinary environment variables 而 setup script 是 before Claude Code launches 跑的 ⇒ 注入在它之後。 ⇒ 把 token 放進 Environment variables 再要 setup script 讀,永遠讀不到。 證據吻合:leo 的變數設對了、值也跟本機同一把(長度 40、頭尾一致), 而腳本回報找不到。 ② exit 非零會讓整個 session 開不起來 官方原文:Exit zero: if the script exits non-zero, the session fails to start. 前一版為了大聲失敗用 exit 1 ⇒ 直接造成 Session initialization failed。 ⇒ 現在一律 exit 0,失敗寫進 /tmp/.isep-setup-report。 本機三向實測: 無變數(雲端真實情況)→ exit 0,印出說明,不擋 session 有變數(未來平台若改行為)→ 設 git 認證並驗證 ls-remote 加 timeout 45(本機曾掛住近 4 分鐘) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
44 lines
2.3 KiB
Bash
44 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
# 貼進 claude.ai → Cloud environments → 你的環境 → Setup script 欄位。
|
|
#
|
|
# 🔴 2026-08-21 查官方文件後的兩個更正(前一版兩處都錯,代價是 leo 一整天):
|
|
#
|
|
# ① **setup script 讀不到 Environment variables。**
|
|
# 官方原文:「Each session copies the environment's values once, **at startup**,
|
|
# into ordinary environment variables」——而 setup script 是
|
|
# 「**before Claude Code launches**」跑的 ⇒ 注入發生在它之後。
|
|
# ⇒ 把 token 放在 Environment variables 再要 setup script 去讀,永遠讀不到。
|
|
#
|
|
# ② **非零結束會讓整個 session 開不起來。**
|
|
# 官方原文:「**Exit zero**: if the script exits non-zero, the session fails to start.」
|
|
# 前一版為了「大聲失敗」用 exit 1 ⇒ 直接把 leo 鎖在門外(Session initialization failed)。
|
|
# ⇒ 現在一律 exit 0,把失敗寫進 /tmp/.isep-setup-report,由 session 內的閘喊出來。
|
|
|
|
set -uo pipefail
|
|
REPORT=/tmp/.isep-setup-report
|
|
: > "$REPORT"
|
|
|
|
say() { echo "$1"; echo "$1" >> "$REPORT"; }
|
|
|
|
if [ -z "${GITEA_TOKEN_CLAUDE_CODE:-}" ]; then
|
|
say "⚠️ setup 階段讀不到 GITEA_TOKEN_CLAUDE_CODE——這是預期的(見檔頭①)。"
|
|
say " ISEP 改由薄殼 repo 的 .claude/settings.json 在 session 啟動時安裝,"
|
|
say " 那時環境變數才存在。本腳本不再嘗試在這裡裝 plugin。"
|
|
exit 0
|
|
fi
|
|
|
|
# 走到這裡表示未來平台改了行為(真的注入了)——那就順手把 git 認證設好,有益無害。
|
|
git config --global url."https://claude-code:${GITEA_TOKEN_CLAUDE_CODE}@git.uncle6.me/".insteadOf \
|
|
"https://git.uncle6.me/" 2>/dev/null || true
|
|
git config --global credential.helper store 2>/dev/null || true
|
|
printf 'https://claude-code:%s@git.uncle6.me\n' "$GITEA_TOKEN_CLAUDE_CODE" > "$HOME/.git-credentials" 2>/dev/null || true
|
|
chmod 600 "$HOME/.git-credentials" 2>/dev/null || true
|
|
|
|
if command -v timeout >/dev/null 2>&1; then TO="timeout 45"; else TO=""; fi
|
|
if GIT_TERMINAL_PROMPT=0 $TO git ls-remote https://git.uncle6.me/inkstone/ISEP.git >/dev/null 2>&1; then
|
|
say "✅ git 認證通:拉得到 inkstone/ISEP"
|
|
else
|
|
say "❌ git 認證不通——檢查 token 值或它是否被撤銷。(不擋 session,繼續啟動)"
|
|
fi
|
|
exit 0
|