Files
gitea-migration/teardown_all.sh
S b799cb7970 feat: add phases 10-11, enhance phase 8 direct-check mode, and update Caddy migration
- Phase 10: local repo cutover (rename origin→github, add Gitea remote, push branches/tags)
- Phase 11: custom runner infrastructure with toolchain-based naming
  (go-node-runner, jvm-android-runner) and repo variables via Gitea API
- Add container_options support to manage_runner.sh for KVM passthrough
- Phase 8: add --allow-direct-checks flag for LAN/split-DNS staging
- Phase 7.5: add Cloudflare TLS block, retry logic for probes, multi-upstream support
- Add toggle_dns.sh helper and update orchestration scripts for phases 10-11

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 14:14:11 -06:00

153 lines
4.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# teardown_all.sh — Tear down migration in reverse order
# Runs phase teardown scripts from phase 11 → phase 1 (or a subset).
#
# Usage:
# ./teardown_all.sh # Tear down everything (phases 11 → 1)
# ./teardown_all.sh --through=5 # Tear down phases 11 → 5 (leave 1-4)
# ./teardown_all.sh --yes # Skip confirmation prompts
# =============================================================================
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# ---------------------------------------------------------------------------
# Parse arguments
# ---------------------------------------------------------------------------
THROUGH=1
AUTO_YES=false
RUN_CLEANUP=false
for arg in "$@"; do
case "$arg" in
--through=*)
THROUGH="${arg#*=}"
if ! [[ "$THROUGH" =~ ^[0-9]+$ ]] || [[ "$THROUGH" -lt 1 ]] || [[ "$THROUGH" -gt 11 ]]; then
log_error "--through must be a number between 1 and 11"
exit 1
fi
;;
--cleanup) RUN_CLEANUP=true ;;
--yes|-y) AUTO_YES=true ;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--through=N Only tear down phases N through 11 (default: 1 = everything)
--cleanup Also run setup/cleanup.sh to uninstall setup prerequisites
--yes, -y Skip all confirmation prompts
--help Show this help
Examples:
$(basename "$0") Tear down everything
$(basename "$0") --through=5 Tear down phases 11-5, leave 1-4
$(basename "$0") --cleanup Full teardown + uninstall prerequisites
$(basename "$0") --yes Non-interactive teardown
EOF
exit 0 ;;
*) log_error "Unknown argument: $arg"; exit 1 ;;
esac
done
# ---------------------------------------------------------------------------
# Confirmation (unless --yes)
# ---------------------------------------------------------------------------
if [[ "$AUTO_YES" == "false" ]]; then
if [[ "$THROUGH" -eq 1 ]]; then
log_warn "This will tear down ALL phases (11 → 1)."
else
log_warn "This will tear down phases 11 → ${THROUGH}."
fi
printf 'Are you sure? [y/N] '
read -r confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
log_info "Teardown cancelled"
exit 0
fi
fi
# Teardown scripts in reverse order (11 → 1)
# Each entry: phase_num|script_path
TEARDOWNS=(
"11|phase11_teardown.sh"
"10|phase10_teardown.sh"
"9|phase9_teardown.sh"
"8|phase8_teardown.sh"
"7|phase7_teardown.sh"
"6|phase6_teardown.sh"
"5|phase5_teardown.sh"
"4|phase4_teardown.sh"
"3|phase3_teardown.sh"
"2|phase2_teardown.sh"
"1|phase1_teardown.sh"
)
PASS=0
FAIL=0
for entry in "${TEARDOWNS[@]}"; do
IFS='|' read -r phase_num script <<< "$entry"
# Skip phases outside the teardown range
if [[ "$phase_num" -lt "$THROUGH" ]]; then
log_info "Skipping Phase ${phase_num} teardown (--through=${THROUGH})"
continue
fi
log_info ">>> Tearing down Phase ${phase_num}..."
if [[ "$AUTO_YES" == "true" ]]; then
# Pass --yes through to each teardown script so prompts are skipped.
if "${SCRIPT_DIR}/${script}" --yes; then
PASS=$((PASS + 1))
else
log_warn "Phase ${phase_num} teardown had issues (continuing)"
FAIL=$((FAIL + 1))
fi
else
# Run interactively — let user respond to each prompt
if "${SCRIPT_DIR}/${script}"; then
PASS=$((PASS + 1))
else
log_warn "Phase ${phase_num} teardown had issues (continuing)"
FAIL=$((FAIL + 1))
fi
fi
printf '\n'
done
# ---------------------------------------------------------------------------
# Optional: Run setup/cleanup.sh to uninstall prerequisites
# ---------------------------------------------------------------------------
if [[ "$RUN_CLEANUP" == "true" ]]; then
log_info ">>> Running setup cleanup (uninstalling prerequisites)..."
cleanup_args=()
if [[ "$AUTO_YES" == "true" ]]; then
cleanup_args+=(--yes)
fi
if "${SCRIPT_DIR}/setup/cleanup.sh" "${cleanup_args[@]}"; then
PASS=$((PASS + 1))
else
log_warn "Setup cleanup had issues (continuing)"
FAIL=$((FAIL + 1))
fi
printf '\n'
fi
# ---------------------------------------------------------------------------
# Summary
# ---------------------------------------------------------------------------
printf '\n'
log_info "Teardown summary: ${PASS} succeeded, ${FAIL} had issues"
if [[ $FAIL -gt 0 ]]; then
log_warn "Some teardowns had issues — check logs above"
else
log_success "All teardowns completed successfully"
fi