From 83f706c6b8a148ec74c6c90d08f8b7c62639e1bb Mon Sep 17 00:00:00 2001 From: S Date: Sun, 1 Mar 2026 08:58:34 -0500 Subject: [PATCH] feat: add idempotent token deletion before generating new Gitea admin token --- phase1_gitea_unraid.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/phase1_gitea_unraid.sh b/phase1_gitea_unraid.sh index 5a74daa..bf7aa77 100755 --- a/phase1_gitea_unraid.sh +++ b/phase1_gitea_unraid.sh @@ -129,6 +129,13 @@ if [[ -n "${GITEA_ADMIN_TOKEN:-}" ]]; then fi if [[ -z "${GITEA_ADMIN_TOKEN:-}" ]]; then + # Delete any stale token with the same name (idempotent re-run safety). + # Gitea returns 409 Conflict if a token with this name already exists. + curl -sf -u "${GITEA_ADMIN_USER}:${GITEA_ADMIN_PASSWORD}" \ + -X DELETE \ + "${GITEA_INTERNAL_URL}/api/v1/users/${GITEA_ADMIN_USER}/tokens/migration-token" \ + -o /dev/null 2>/dev/null || true + # Generate token using basic auth (username:password). # The .sha1 field in the response contains the full token — this is the # ONLY time it's returned, so we must save it immediately.