52 lines
1.8 KiB
Bash
Executable File
52 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# =============================================================================
|
|
# phase4_teardown.sh — Delete migrated repos from primary + mirrors from Fedora
|
|
# Destructive: permanently deletes repositories.
|
|
# Prompts for confirmation before each deletion.
|
|
# Safe to run if repos have already been deleted (no errors).
|
|
# =============================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
source "${SCRIPT_DIR}/lib/common.sh"
|
|
|
|
load_env
|
|
require_vars GITEA_ADMIN_TOKEN GITEA_BACKUP_ADMIN_TOKEN \
|
|
GITEA_INTERNAL_URL GITEA_BACKUP_INTERNAL_URL \
|
|
GITEA_ORG_NAME GITEA_ADMIN_USER \
|
|
REPO_NAMES
|
|
|
|
log_warn "=== Phase 4 Teardown: Repos + Mirrors ==="
|
|
|
|
read -ra REPOS <<< "$REPO_NAMES"
|
|
|
|
printf 'This will DELETE all migrated repos and mirrors. Continue? [y/N] '
|
|
read -r confirm
|
|
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
|
log_info "Teardown cancelled"
|
|
exit 0
|
|
fi
|
|
|
|
for repo in "${REPOS[@]}"; do
|
|
log_info "--- Tearing down: ${repo} ---"
|
|
|
|
# Delete repo from primary (under org)
|
|
if gitea_api GET "/repos/${GITEA_ORG_NAME}/${repo}" >/dev/null 2>&1; then
|
|
gitea_api DELETE "/repos/${GITEA_ORG_NAME}/${repo}" >/dev/null || true
|
|
log_success "Deleted ${GITEA_ORG_NAME}/${repo} from primary"
|
|
else
|
|
log_info "Repo ${GITEA_ORG_NAME}/${repo} not found on primary — already deleted"
|
|
fi
|
|
|
|
# Delete mirror from Fedora (under admin user)
|
|
if gitea_backup_api GET "/repos/${GITEA_ADMIN_USER}/${repo}" >/dev/null 2>&1; then
|
|
gitea_backup_api DELETE "/repos/${GITEA_ADMIN_USER}/${repo}" >/dev/null || true
|
|
log_success "Deleted mirror ${GITEA_ADMIN_USER}/${repo} from Fedora"
|
|
else
|
|
log_info "Mirror ${GITEA_ADMIN_USER}/${repo} not found on Fedora — already deleted"
|
|
fi
|
|
done
|
|
|
|
log_success "Phase 4 teardown complete"
|