From 40fe8477554030e27497759c8e4b07897d946971 Mon Sep 17 00:00:00 2001 From: S Date: Thu, 26 Feb 2026 15:33:51 -0600 Subject: [PATCH] feat: add orchestration (run_all.sh, teardown_all.sh) Co-Authored-By: Claude Opus 4.6 --- run_all.sh | 161 ++++++++++++++++++++++++++++++++++++++++++++++++ teardown_all.sh | 134 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 295 insertions(+) create mode 100755 run_all.sh create mode 100755 teardown_all.sh diff --git a/run_all.sh b/run_all.sh new file mode 100755 index 0000000..caa78f8 --- /dev/null +++ b/run_all.sh @@ -0,0 +1,161 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ============================================================================= +# run_all.sh — Orchestrate the full Gitea migration pipeline +# Runs: setup → preflight → phase 1-9 (each with post-check) sequentially. +# Stops on first failure, prints summary of what completed. +# +# Usage: +# ./run_all.sh # Full run: setup + preflight + phases 1-9 +# ./run_all.sh --skip-setup # Skip setup scripts, start at preflight +# ./run_all.sh --start-from=3 # Run preflight, then start at phase 3 +# ./run_all.sh --skip-setup --start-from=5 +# ============================================================================= + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +source "${SCRIPT_DIR}/lib/common.sh" + +# --------------------------------------------------------------------------- +# Parse arguments +# --------------------------------------------------------------------------- +SKIP_SETUP=false +START_FROM=0 + +for arg in "$@"; do + case "$arg" in + --skip-setup) SKIP_SETUP=true ;; + --start-from=*) + START_FROM="${arg#*=}" + if ! [[ "$START_FROM" =~ ^[0-9]+$ ]]; then + log_error "--start-from must be a number (1-9)" + exit 1 + fi + ;; + --help|-h) + cat <>> Running: ${name}" + if "${SCRIPT_DIR}/${script}"; then + record_step "$name" "PASS" + printf '\n' + else + record_step "$name" "FAIL" + log_error ">>> FAILED: ${name}" + print_summary + exit 1 + fi +} + +# --------------------------------------------------------------------------- +# Summary printer — shows pass/fail for each step that ran +# --------------------------------------------------------------------------- +print_summary() { + printf '\n' + log_info "===== Execution Summary =====" + for i in "${!STEP_NAMES[@]}"; do + if [[ "${STEP_RESULTS[$i]}" == "PASS" ]]; then + log_success " ${STEP_NAMES[$i]}" + else + log_error " ${STEP_NAMES[$i]} — FAILED" + fi + done + printf '\n' +} + +# --------------------------------------------------------------------------- +# Step 0: Setup (configure_env + machine prerequisites) +# Skipped if --skip-setup or --start-from is set (assumes already done). +# configure_env is interactive — don't run it in automated pipelines. +# --------------------------------------------------------------------------- +if [[ "$SKIP_SETUP" == "false" ]] && [[ "$START_FROM" -eq 0 ]]; then + log_info "=== Step 0: Setup ===" + + # configure_env.sh is interactive — ask user if they want to run it + # since they may have already filled in .env manually + if [[ -f "${SCRIPT_DIR}/.env" ]]; then + log_info ".env already exists — skipping configure_env.sh" + else + run_step "Configure .env" "setup/configure_env.sh" + fi + + run_step "Setup MacBook" "setup/macbook.sh" + run_step "Setup Unraid" "setup/unraid.sh" + run_step "Setup Fedora" "setup/fedora.sh" +else + log_info "Skipping setup (--skip-setup or --start-from=${START_FROM})" +fi + +# --------------------------------------------------------------------------- +# Preflight — always runs (validates .env and infrastructure) +# Even with --start-from, preflight ensures the environment is healthy. +# --------------------------------------------------------------------------- +log_info "=== Preflight ===" +run_step "Preflight checks" "preflight.sh" + +# --------------------------------------------------------------------------- +# Phases 1-9 — run sequentially, each followed by its post-check +# The phase scripts are the "do" step, post-checks verify success. +# --------------------------------------------------------------------------- +PHASES=( + "1|Phase 1: Gitea on Unraid|phase1_gitea_unraid.sh|phase1_post_check.sh" + "2|Phase 2: Gitea on Fedora|phase2_gitea_fedora.sh|phase2_post_check.sh" + "3|Phase 3: Runners|phase3_runners.sh|phase3_post_check.sh" + "4|Phase 4: Migrate Repos|phase4_migrate_repos.sh|phase4_post_check.sh" + "5|Phase 5: Migrate Pipelines|phase5_migrate_pipelines.sh|phase5_post_check.sh" + "6|Phase 6: GitHub Mirrors|phase6_github_mirrors.sh|phase6_post_check.sh" + "7|Phase 7: Branch Protection|phase7_branch_protection.sh|phase7_post_check.sh" + "8|Phase 8: Cutover|phase8_cutover.sh|phase8_post_check.sh" + "9|Phase 9: Security|phase9_security.sh|phase9_post_check.sh" +) + +for phase_entry in "${PHASES[@]}"; do + IFS='|' read -r phase_num phase_name phase_script post_check <<< "$phase_entry" + + # Skip phases before --start-from + if [[ "$phase_num" -lt "$START_FROM" ]]; then + log_info "Skipping ${phase_name} (--start-from=${START_FROM})" + continue + fi + + run_step "$phase_name" "$phase_script" + run_step "${phase_name} — post-check" "$post_check" +done + +# --------------------------------------------------------------------------- +# All done +# --------------------------------------------------------------------------- +print_summary +log_success "Migration complete! Gitea is live." diff --git a/teardown_all.sh b/teardown_all.sh new file mode 100755 index 0000000..c2fdb7f --- /dev/null +++ b/teardown_all.sh @@ -0,0 +1,134 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ============================================================================= +# teardown_all.sh — Tear down migration in reverse order +# Runs phase teardown scripts from phase 9 → phase 1 (or a subset). +# +# Usage: +# ./teardown_all.sh # Tear down everything (phases 9 → 1) +# ./teardown_all.sh --through=5 # Tear down phases 9 → 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 + +for arg in "$@"; do + case "$arg" in + --through=*) + THROUGH="${arg#*=}" + if ! [[ "$THROUGH" =~ ^[0-9]+$ ]] || [[ "$THROUGH" -lt 1 ]] || [[ "$THROUGH" -gt 9 ]]; then + log_error "--through must be a number between 1 and 9" + exit 1 + fi + ;; + --yes|-y) AUTO_YES=true ;; + --help|-h) + cat <>> Tearing down Phase ${phase_num}..." + + if [[ "$AUTO_YES" == "true" ]]; then + # Pipe 'y' to all prompts in the teardown script + if echo "y" | "${SCRIPT_DIR}/${script}"; 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 + +# --------------------------------------------------------------------------- +# 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