- 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>
206 lines
8.0 KiB
Bash
Executable File
206 lines
8.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# =============================================================================
|
|
# run_all.sh — Orchestrate the full Gitea migration pipeline
|
|
# Runs: setup → preflight → phase 1-11 (each with post-check) sequentially.
|
|
# Stops on first failure, prints summary of what completed.
|
|
#
|
|
# Usage:
|
|
# ./run_all.sh # Full run: setup + preflight + phases 1-11
|
|
# ./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
|
|
# ./run_all.sh --dry-run # Read-only infrastructure state check
|
|
# =============================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
source "${SCRIPT_DIR}/lib/common.sh"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# OS check — the control plane must be macOS (uses brew, launchctl, macOS sed)
|
|
# ---------------------------------------------------------------------------
|
|
require_local_os "Darwin" "run_all.sh must run from macOS (the control plane)"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Parse arguments
|
|
# ---------------------------------------------------------------------------
|
|
SKIP_SETUP=false
|
|
START_FROM=0
|
|
START_FROM_SET=false
|
|
ALLOW_DIRECT_CHECKS=false
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--skip-setup) SKIP_SETUP=true ;;
|
|
--allow-direct-checks) ALLOW_DIRECT_CHECKS=true ;;
|
|
--dry-run)
|
|
exec "${SCRIPT_DIR}/post-migration-check.sh"
|
|
;;
|
|
--start-from=*)
|
|
START_FROM="${arg#*=}"
|
|
START_FROM_SET=true
|
|
if ! [[ "$START_FROM" =~ ^[0-9]+$ ]]; then
|
|
log_error "--start-from must be a number (1-11)"
|
|
exit 1
|
|
fi
|
|
if [[ "$START_FROM" -lt 1 ]] || [[ "$START_FROM" -gt 11 ]]; then
|
|
log_error "--start-from must be between 1 and 11"
|
|
exit 1
|
|
fi
|
|
;;
|
|
--help|-h)
|
|
cat <<EOF
|
|
Usage: $(basename "$0") [options]
|
|
|
|
Options:
|
|
--skip-setup Skip configure_env + machine setup, start at preflight
|
|
--start-from=N Skip phases before N (still runs preflight)
|
|
--allow-direct-checks Pass --allow-direct-checks to Phase 8 scripts
|
|
(LAN/split-DNS staging mode)
|
|
--dry-run Run read-only infrastructure check (no mutations)
|
|
--help Show this help
|
|
|
|
Examples:
|
|
$(basename "$0") Full run
|
|
$(basename "$0") --skip-setup Skip setup, start at preflight
|
|
$(basename "$0") --start-from=3 Run preflight, then phases 3-11
|
|
$(basename "$0") --allow-direct-checks LAN mode: use direct Caddy-IP checks
|
|
$(basename "$0") --dry-run Check current state without changing anything
|
|
EOF
|
|
exit 0 ;;
|
|
*) log_error "Unknown argument: $arg"; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Execution tracking
|
|
# We track each step's status for the summary at the end.
|
|
# ---------------------------------------------------------------------------
|
|
declare -a STEP_NAMES
|
|
declare -a STEP_RESULTS
|
|
|
|
record_step() {
|
|
local name="$1" result="$2"
|
|
STEP_NAMES+=("$name")
|
|
STEP_RESULTS+=("$result")
|
|
}
|
|
|
|
# Run a script, record pass/fail, stop on failure.
|
|
# Usage: run_step "Step Name" "script.sh" [args...]
|
|
run_step() {
|
|
local name="$1" script="$2"
|
|
shift 2
|
|
log_info ">>> 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"
|
|
run_step "Cross-host SSH trust" "setup/cross_host_ssh.sh"
|
|
else
|
|
if [[ "$START_FROM_SET" == "true" ]]; then
|
|
log_info "Skipping setup (--skip-setup or --start-from=${START_FROM})"
|
|
else
|
|
log_info "Skipping setup (--skip-setup)"
|
|
fi
|
|
fi
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Preflight — always runs (validates .env and infrastructure)
|
|
# Even with --start-from, preflight ensures the environment is healthy.
|
|
# When resuming (--start-from > 1), port-free checks are skipped because
|
|
# earlier phases have Gitea already running on those ports.
|
|
# ---------------------------------------------------------------------------
|
|
log_info "=== Preflight ==="
|
|
if [[ "$START_FROM" -gt 1 ]]; then
|
|
log_info "Resuming from phase ${START_FROM} — skipping port-free checks"
|
|
run_step "Preflight checks" "preflight.sh" --skip-port-checks
|
|
else
|
|
run_step "Preflight checks" "preflight.sh"
|
|
fi
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Phases 1-11 — 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"
|
|
"10|Phase 10: Local Repo Cutover|phase10_local_repo_cutover.sh|phase10_post_check.sh"
|
|
"11|Phase 11: Custom Runners|phase11_custom_runners.sh|phase11_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
|
|
|
|
# Phase 8 scripts accept --allow-direct-checks for LAN/split-DNS setups.
|
|
if [[ "$phase_num" -eq 8 ]] && [[ "$ALLOW_DIRECT_CHECKS" == "true" ]]; then
|
|
run_step "$phase_name" "$phase_script" --allow-direct-checks
|
|
run_step "${phase_name} — post-check" "$post_check" --allow-direct-checks
|
|
else
|
|
run_step "$phase_name" "$phase_script"
|
|
run_step "${phase_name} — post-check" "$post_check"
|
|
fi
|
|
done
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# All done
|
|
# ---------------------------------------------------------------------------
|
|
print_summary
|
|
log_success "Migration complete! Gitea is live."
|