83 lines
2.3 KiB
Bash
Executable File
83 lines
2.3 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"
|
|
|
|
# Parse arguments
|
|
AUTO_YES=false
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--yes|-y) AUTO_YES=true ;;
|
|
--help|-h)
|
|
cat <<EOF
|
|
Usage: $(basename "$0") [options]
|
|
|
|
Options:
|
|
--yes, -y Skip all confirmation prompts
|
|
--help, -h Show this help
|
|
EOF
|
|
exit 0
|
|
;;
|
|
*)
|
|
log_error "Unknown argument: $arg"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
confirm_action() {
|
|
local prompt="$1"
|
|
if [[ "$AUTO_YES" == "true" ]]; then
|
|
log_info "Auto-confirmed (--yes): ${prompt}"
|
|
return 0
|
|
fi
|
|
printf '%s' "$prompt"
|
|
read -r confirm
|
|
[[ "$confirm" =~ ^[Yy]$ ]]
|
|
}
|
|
|
|
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"
|
|
|
|
if ! confirm_action 'This will DELETE all migrated repos and mirrors. Continue? [y/N] '; 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"
|