- teardown_all.sh: replace `yes |` pipeline with `< <(yes)` process
substitution to avoid SIGPIPE (exit 141) false failures under pipefail
- phase6_teardown.sh: extract push mirror `.id` instead of `.remote_name`
to match the DELETE /push_mirrors/{id} API contract
- phase5_migrate_pipelines.sh: expand sed regex from `[a-z_]*` to
`[a-z_.]*` to handle nested GitHub contexts like
`github.event.pull_request.number`
- lib/common.sh: render_template now requires explicit variable list to
prevent envsubst from eating Nginx variables ($host, $proxy_add_...)
- backup scripts: remove MacBook relay, use direct Unraid↔Fedora SCP;
fix dump path to write to /data/ (mounted volume) instead of /tmp/
(container-only); add unzip -t integrity verification
- preflight.sh: add --skip-port-checks flag for resuming with
--start-from (ports already bound by earlier phases)
- run_all.sh: update run_step to pass extra args; use --skip-port-checks
when --start-from > 1
- post-checks (phase4/7/9): wrap API calls in helper functions with
>/dev/null redirection instead of passing -o /dev/null as API data
- phase8: replace GitHub archiving with [MIRROR] description marking
and disable wiki/projects/Pages (archived repos reject push mirrors)
- restore_to_primary.sh: add require_vars for Fedora SSH variables
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
176 lines
6.5 KiB
Bash
Executable File
176 lines
6.5 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-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"
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 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
|
|
|
|
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 <<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)
|
|
--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-9
|
|
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"
|
|
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.
|
|
# 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-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."
|