gitea: retry token prompts instead of accepting one empty answer

Live symptom: pasting the GitHub PAT over SSH showed the token text
landing on the terminal *after* "No GitHub token entered" had already
printed — the prompt's read() returned empty a beat before the paste
actually arrived (a paste/Enter race that isn't specific to this box,
just common over higher-latency SSH sessions). A single empty answer
was treated as "user has no token" and the install moved on silently.

Both token prompts (GitHub token, and the Gitea-token manual fallback)
now retry up to 3 times interactively before giving up, and strip
whitespace from what was captured in case the paste carried a stray
leading/trailing newline. Unattended installs still take one shot, same
as before, since nobody's there to retry.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YEQNc4NfBST1m9NtCZVYa8
This commit is contained in:
Claude
2026-08-17 17:27:56 +00:00
parent dcf643cde4
commit f0ef647f60
+22 -2
View File
@@ -127,6 +127,26 @@ _gitea_sync_vendor_src() {
echo "$(cd "$_self_dir/.." && pwd)/vendor/ai-stack/gitea-github-sync.sh"
}
# Prompt for a token with retries — pasted tokens over SSH sometimes race the
# prompt (the terminal delivers the paste a beat after an already-submitted
# empty line, so the token shows up echoed on the *next* line instead of
# being read). A single empty answer used to be taken as "no token", silently
# — this gives it up to 3 tries before actually giving up, and strips
# whitespace in case the paste carried a stray leading/trailing newline.
_gitea_prompt_token() {
local _question="$1" _varname="$2"
local _max=1 _tries=0 _val=""
[ "$UNATTENDED" != true ] && _max=3
while [[ $_tries -lt $_max ]]; do
prompt_text "$_question" "" _val
_val="$(printf '%s' "$_val" | tr -d '[:space:]')"
[[ -n "$_val" ]] && break
_tries=$((_tries + 1))
[[ $_tries -lt $_max ]] && log_warning " Nothing came through — if you pasted it, try again (a paste can race the prompt over SSH)."
done
eval "$_varname='$_val'"
}
# ── Own systemd timer, not gitea-github-sync.sh's built-in --install-timer ──
# The vendor script's own timer installer always runs the script bare (no
# --pull-only/--push-only), i.e. always both directions — there's no way to
@@ -398,7 +418,7 @@ EOF
log_warning "Automatic token generation didn't work (older Gitea image?) — generate one"
log_warning "by hand: log into http://localhost:${WEB_PORT} as $GITEA_ADMIN_USER, then"
log_warning "Settings -> Applications -> Generate New Token (repo + user write access)."
prompt_text " Paste the GITEA token here (not the GitHub one — that's next):" "" GITEA_TOKEN
_gitea_prompt_token " Paste the GITEA token here (not the GitHub one — that's next):" GITEA_TOKEN
fi
# ── GitHub token ─────────────────────────────────────────────────────────
@@ -407,7 +427,7 @@ EOF
log_info "REST API too, which SSH can't do). Generate one at https://github.com/settings/tokens"
log_info "with 'repo' scope if you don't already have one handy."
local GITHUB_TOKEN=""
prompt_text " GitHub token:" "" GITHUB_TOKEN
_gitea_prompt_token " GitHub token:" GITHUB_TOKEN
if [[ -z "$GITHUB_TOKEN" ]]; then
log_warning "No GitHub token entered — Gitea itself is still up, but the sync script won't"
log_warning "work until you add one to $DIR/.env and re-run this installer (update mode)."