changemaker.lite/scripts/gitea-init.sh
bunker-admin 4ccc433eb9 fix(gitea): fall back to INITIAL_ADMIN_PASSWORD for gitea-init
Previously both compose files defaulted GITEA_ADMIN_PASSWORD to empty,
and scripts/gitea-init.sh silently skipped admin creation on blank input.
If config.sh failed to propagate the password (e.g. Docs Comments not
enabled, or --admin-password omitted), fresh installs ended up with a
Gitea container running but zero users — and the admin GUI's Gitea setup
wizard had no token to progress.

Changes:
- docker-compose.yml + docker-compose.prod.yml: GITEA_ADMIN_PASSWORD now
  falls back to INITIAL_ADMIN_PASSWORD when unset
- .env.example: declare GITEA_ADMIN_PASSWORD= with explanatory comment so
  users discover the override
- scripts/gitea-init.sh: silent skip becomes a loud WARN so a broken
  config is visible in compose logs

Bunker Admin
2026-04-23 10:54:24 -06:00

54 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
# =============================================================================
# Gitea Admin User Initialization
# =============================================================================
# Runs as a separate init container (like nocodb-init) AFTER gitea-app is healthy.
# Shares the gitea-data volume so the app.ini config is available.
# Creates the admin user if it doesn't exist, then exits.
# =============================================================================
set -e
PREFIX="[gitea-init]"
log() { echo "$PREFIX $1"; }
# The gitea binary needs app.ini to know the database connection.
# On the Gitea Docker image, GITEA_CUSTOM defaults to /data/gitea
# and app.ini lives at /data/gitea/conf/app.ini (created by gitea-app's entrypoint).
# Gitea refuses to run as root. The init container bypasses the Gitea entrypoint,
# so we must drop privileges ourselves. Re-exec as 'git' user via su-exec.
if [ "$(id -u)" = "0" ]; then
exec su-exec git "$0" "$@"
fi
export GITEA_CUSTOM="${GITEA_CUSTOM:-/data/gitea}"
if [ ! -f "$GITEA_CUSTOM/conf/app.ini" ]; then
log "ERROR: No app.ini found at $GITEA_CUSTOM/conf/app.ini"
log "This means gitea-app hasn't completed its first startup yet."
exit 1
fi
log "Found app.ini at $GITEA_CUSTOM/conf/app.ini"
if [ -z "$GITEA_ADMIN_USER" ] || [ -z "$GITEA_ADMIN_PASSWORD" ] || [ -z "$GITEA_ADMIN_EMAIL" ]; then
log "WARN: GITEA_ADMIN_USER/PASSWORD/EMAIL is blank — admin user will NOT be created."
log "WARN: The Gitea Setup wizard in the admin GUI cannot proceed without this admin."
log "WARN: Fix: set GITEA_ADMIN_PASSWORD (or INITIAL_ADMIN_PASSWORD) in .env, then rerun:"
log "WARN: docker compose up -d gitea-init"
exit 0
fi
# Create admin user (idempotent — returns non-zero if user exists)
log "Creating admin user '${GITEA_ADMIN_USER}' (${GITEA_ADMIN_EMAIL})..."
if gitea admin user create --admin \
--username "$GITEA_ADMIN_USER" \
--password "$GITEA_ADMIN_PASSWORD" \
--email "$GITEA_ADMIN_EMAIL" \
--must-change-password=false 2>&1; then
log "Admin user created successfully"
else
log "Admin user already exists (or creation skipped)"
fi
log "Done"