feat: add Phase 2 — Gitea on Fedora (backup instance)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
65
phase2_teardown.sh
Executable file
65
phase2_teardown.sh
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# =============================================================================
|
||||
# phase2_teardown.sh — Tear down Gitea on Fedora
|
||||
# Destructive: stops container, optionally removes all data.
|
||||
# Prompts for confirmation before each destructive action.
|
||||
# Safe to run against an already-torn-down instance (no errors).
|
||||
# =============================================================================
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "${SCRIPT_DIR}/lib/common.sh"
|
||||
|
||||
load_env
|
||||
require_vars FEDORA_IP FEDORA_SSH_USER FEDORA_GITEA_DATA_PATH
|
||||
|
||||
DATA_PATH="$FEDORA_GITEA_DATA_PATH"
|
||||
|
||||
log_warn "=== Phase 2 Teardown: Gitea on Fedora ==="
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Step 1: Stop and remove the Gitea container
|
||||
# ---------------------------------------------------------------------------
|
||||
# Check if docker-compose file exists (skip if already torn down)
|
||||
if ssh_exec FEDORA "test -f '${DATA_PATH}/docker-compose.yml'" 2>/dev/null; then
|
||||
printf 'This will stop Gitea on Fedora. Continue? [y/N] '
|
||||
read -r confirm
|
||||
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
||||
# Try modern "docker compose" first, fall back to standalone
|
||||
ssh_exec FEDORA "cd '${DATA_PATH}' && docker compose down 2>/dev/null || docker-compose down" || true
|
||||
log_success "Gitea container stopped and removed"
|
||||
else
|
||||
log_info "Skipped container shutdown"
|
||||
fi
|
||||
else
|
||||
log_info "No docker-compose.yml found — container already removed"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Step 2: Optionally remove all Gitea data
|
||||
# This is irreversible — removes repos, database, config, everything.
|
||||
# ---------------------------------------------------------------------------
|
||||
if ssh_exec FEDORA "test -d '${DATA_PATH}'" 2>/dev/null; then
|
||||
printf 'Remove ALL Gitea data at %s on Fedora? This is IRREVERSIBLE. [y/N] ' "$DATA_PATH"
|
||||
read -r confirm
|
||||
if [[ "$confirm" =~ ^[Yy]$ ]]; then
|
||||
ssh_exec FEDORA "rm -rf '${DATA_PATH}'"
|
||||
log_success "All Gitea data removed from Fedora"
|
||||
else
|
||||
log_info "Data preserved at ${DATA_PATH}"
|
||||
fi
|
||||
else
|
||||
log_info "Data directory already removed"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Step 3: Clear the auto-populated backup API token from .env
|
||||
# The token is useless after teardown — clear it so phase2 generates a new one.
|
||||
# ---------------------------------------------------------------------------
|
||||
if [[ -n "${GITEA_BACKUP_ADMIN_TOKEN:-}" ]]; then
|
||||
save_env_var "GITEA_BACKUP_ADMIN_TOKEN" ""
|
||||
log_success "GITEA_BACKUP_ADMIN_TOKEN cleared from .env"
|
||||
fi
|
||||
|
||||
log_success "Phase 2 teardown complete"
|
||||
Reference in New Issue
Block a user