Files
gitea-migration/phase1_teardown.sh
S 63f708e556 feat: add Phase 1 — Gitea on Unraid
- phase1_gitea_unraid.sh: 9-step deploy (dirs, docker-compose, app.ini,
  container start, wait, admin user, API token, save to .env, create org).
  Every step has idempotency check — running twice changes nothing.
- phase1_post_check.sh: 5 independent verification checks
- phase1_teardown.sh: stop container + optionally remove data, with prompts

Also adds inline comments to lib/common.sh and preflight.sh explaining
WHY decisions were made (SSH flags, API tmpfile pattern, port checks, etc.)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 15:12:02 -06:00

66 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# phase1_teardown.sh — Tear down Gitea on Unraid
# 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 UNRAID_IP UNRAID_SSH_USER UNRAID_GITEA_DATA_PATH
DATA_PATH="$UNRAID_GITEA_DATA_PATH"
log_warn "=== Phase 1 Teardown: Gitea on Unraid ==="
# ---------------------------------------------------------------------------
# Step 1: Stop and remove the Gitea container
# ---------------------------------------------------------------------------
# Check if docker-compose file exists (skip if already torn down)
if ssh_exec UNRAID "test -f '${DATA_PATH}/docker-compose.yml'" 2>/dev/null; then
printf 'This will stop Gitea on Unraid. Continue? [y/N] '
read -r confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
# Try modern "docker compose" first, fall back to standalone
ssh_exec UNRAID "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 UNRAID "test -d '${DATA_PATH}'" 2>/dev/null; then
printf 'Remove ALL Gitea data at %s? This is IRREVERSIBLE. [y/N] ' "$DATA_PATH"
read -r confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
ssh_exec UNRAID "rm -rf '${DATA_PATH}'"
log_success "All Gitea data removed from Unraid"
else
log_info "Data preserved at ${DATA_PATH}"
fi
else
log_info "Data directory already removed"
fi
# ---------------------------------------------------------------------------
# Step 3: Clear the auto-populated API token from .env
# The token is useless after teardown — clear it so phase1 generates a new one.
# ---------------------------------------------------------------------------
if [[ -n "${GITEA_ADMIN_TOKEN:-}" ]]; then
save_env_var "GITEA_ADMIN_TOKEN" ""
log_success "GITEA_ADMIN_TOKEN cleared from .env"
fi
log_success "Phase 1 teardown complete"