From def70ab4e2757ba1966fa18478e74548a0b6d368 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 17:19:01 +0000 Subject: [PATCH 1/2] gitea: fix token-name collision that swallowed the GitHub token prompt generate-access-token used a fixed --token-name "sync", which Gitea rejects on a second call for the same user (e.g. a retry against an already-existing admin account, now common after the readiness-wait fix). The failure was silent: it fell through to a manually-labeled "Paste the Gitea token here" prompt appearing immediately before the real "GitHub token:" prompt, so a pasted GitHub PAT could land on the wrong prompt and leave GITHUB_TOKEN empty with no clear reason why. Token name now includes a timestamp so it's always unique, and the fallback prompt is relabeled to make clear it wants a Gitea token, not the GitHub one. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01YEQNc4NfBST1m9NtCZVYa8 --- services/gitea.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/gitea.sh b/services/gitea.sh index c60f65e..1c6182f 100644 --- a/services/gitea.sh +++ b/services/gitea.sh @@ -356,15 +356,20 @@ EOF log_success "Admin account created: $GITEA_ADMIN_USER" fi + # Token name includes a timestamp so a retry against an account that + # already has a "sync" token from an earlier partial run (see the + # already-exists branch above) never collides — Gitea rejects a second + # token with a name that's already taken for that user, which used to + # silently fall through to the manual-paste prompt below on every retry. local GITEA_TOKEN="" GITEA_TOKEN="$(docker exec -u git gitea gitea admin user generate-access-token \ - --username "$GITEA_ADMIN_USER" --token-name sync \ + --username "$GITEA_ADMIN_USER" --token-name "sync-$(date +%s)" \ --scopes write:repository,write:user --raw 2>/dev/null)" if [[ -z "$GITEA_TOKEN" ]]; then 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:" "" GITEA_TOKEN + prompt_text " Paste the GITEA token here (not the GitHub one — that's next):" "" GITEA_TOKEN fi # ── GitHub token ───────────────────────────────────────────────────────── From dcf643cde4545cd694f58b319a651cd2e7f57177 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 17 Aug 2026 17:22:27 +0000 Subject: [PATCH 2/2] gitea: offer to run the sync immediately after configuring it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sync direction step only ever set up the timer (or printed manual instructions) — there was no way to actually confirm tokens/config work without waiting for the first scheduled run or invoking the script by hand afterward. Add a post-configure prompt: dry-run preview (--list), run for real right now, or skip. Defaults to dry-run interactively; defaults to skip under UNATTENDED so a headless install with no GitHub token configured doesn't spam preflight errors. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01YEQNc4NfBST1m9NtCZVYa8 --- services/gitea.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/services/gitea.sh b/services/gitea.sh index 1c6182f..c9188fe 100644 --- a/services/gitea.sh +++ b/services/gitea.sh @@ -216,6 +216,34 @@ _gitea_run_sync_direction_step() { log_info " cd $DIR && bash gitea-github-sync.sh $FLAG" [[ -z "$FLAG" ]] && log_info " (no flag needed for both directions)" fi + + # ── Run it now, off the timer — lets you confirm tokens/config are + # actually correct right here instead of waiting for the first + # scheduled run (or a manual invocation later) to find out. + echo "" + echo " Run a sync now?" + echo " 1) Dry-run preview only (--list) — shows what would sync, no changes" + echo " 2) Run for real now ($DIR_DESC)" + echo " 3) Skip — don't run anything now" + local _RUN_DEFAULT="1" + [ "$UNATTENDED" = true ] && _RUN_DEFAULT="3" + local _RUN_NOW="" + prompt_text " Choice [$_RUN_DEFAULT]:" "$_RUN_DEFAULT" _RUN_NOW + case "$_RUN_NOW" in + 2) + log_info "Running sync now ($DIR_DESC)..." + sudo -u "$ACTUAL_USER" env HOME="$ACTUAL_HOME" SYNC_ENV="$DIR/.env" \ + bash "$DIR/gitea-github-sync.sh" $FLAG \ + && log_success "Sync run complete." \ + || log_warning "Sync run failed — check the output above, or ~/.config/gitea-github-sync/sync.log" + ;; + 3) log_info "Skipped — run it later with the commands above." ;; + *) + log_info "Dry-run preview (--list)..." + sudo -u "$ACTUAL_USER" env HOME="$ACTUAL_HOME" SYNC_ENV="$DIR/.env" \ + bash "$DIR/gitea-github-sync.sh" --list + ;; + esac } install_gitea() { @@ -233,6 +261,7 @@ install_gitea() { echo "[DRY-RUN] Would prompt for a GitHub token and copy in gitea-github-sync.sh" echo "[DRY-RUN] Would ask sync direction (GitHub->Gitea / Gitea->GitHub / both) and whether" echo "[DRY-RUN] to install a systemd timer for automatic sync, or print manual instructions" + echo "[DRY-RUN] Would offer to run a sync now (dry-run preview or for real), off-schedule" echo "[DRY-RUN] Would write $DIR/README.md" return 0 fi