feat: add --yes support to teardown scripts

This commit is contained in:
S
2026-03-02 11:32:01 -05:00
parent 57ceae3bd5
commit 62c9e0f2bb
11 changed files with 315 additions and 71 deletions

View File

@@ -89,17 +89,6 @@ else
log_success "docker-compose.yml deployed"
fi
# Symlink into Unraid Compose Manager plugin so it appears on the dashboard.
# Idempotent: ln -sf overwrites existing symlink. Skipped if plugin not installed.
COMPOSE_PLUGIN_PROJECTS="/boot/config/plugins/compose.manager/projects"
if ssh_exec UNRAID "test -d '${COMPOSE_PLUGIN_PROJECTS}'"; then
ssh_exec UNRAID "mkdir -p '${COMPOSE_PLUGIN_PROJECTS}/gitea' && \
ln -sf '${DATA_PATH}/docker-compose.yml' '${COMPOSE_PLUGIN_PROJECTS}/gitea/docker-compose.yml'"
log_success "Registered with Unraid Compose Manager (dashboard symlink)"
else
log_info "Compose Manager plugin not found — skipping dashboard registration"
fi
# ---------------------------------------------------------------------------
# Step 4: Render + SCP app.ini
# ---------------------------------------------------------------------------

View File

@@ -11,6 +11,39 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# Parse arguments
AUTO_YES=false
for arg in "$@"; do
case "$arg" in
--yes|-y) AUTO_YES=true ;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--yes, -y Skip all confirmation prompts
--help, -h Show this help
EOF
exit 0
;;
*)
log_error "Unknown argument: $arg"
exit 1
;;
esac
done
confirm_action() {
local prompt="$1"
if [[ "$AUTO_YES" == "true" ]]; then
log_info "Auto-confirmed (--yes): ${prompt}"
return 0
fi
printf '%s' "$prompt"
read -r confirm
[[ "$confirm" =~ ^[Yy]$ ]]
}
load_env
require_vars UNRAID_IP UNRAID_SSH_USER UNRAID_GITEA_DATA_PATH
@@ -26,9 +59,7 @@ TEARDOWN_FAILED=false
# ---------------------------------------------------------------------------
# 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
if confirm_action 'This will stop Gitea on Unraid. Continue? [y/N] '; then
# Try modern "docker compose" first, fall back to standalone
if ssh_exec UNRAID "cd '${DATA_PATH}' && docker compose down 2>/dev/null || docker-compose down"; then
log_success "Gitea container stopped and removed"
@@ -44,9 +75,7 @@ else
existing_container=$(ssh_exec UNRAID "docker ps -a --filter 'name=^/gitea$' --format '{{.ID}}'" 2>/dev/null || true)
if [[ -n "$existing_container" ]]; then
log_warn "docker-compose.yml not found, but gitea container still exists."
printf 'Force-remove gitea container directly? [y/N] '
read -r confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
if confirm_action 'Force-remove gitea container directly? [y/N] '; then
if ssh_exec UNRAID "docker rm -f gitea" >/dev/null 2>&1; then
log_success "Gitea container force-removed"
else
@@ -70,9 +99,7 @@ if [[ -n "$running_container" ]]; then
log_warn "Gitea container is still running — refusing to remove data directory."
log_warn "Stop the container first, then re-run teardown to remove data."
elif 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
if confirm_action "$(printf 'Remove ALL Gitea data at %s? This is IRREVERSIBLE. [y/N] ' "$DATA_PATH")"; then
if ssh_exec UNRAID "rm -rf '${DATA_PATH}'"; then
log_success "All Gitea data removed from Unraid"
else

View File

@@ -11,6 +11,39 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# Parse arguments
AUTO_YES=false
for arg in "$@"; do
case "$arg" in
--yes|-y) AUTO_YES=true ;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--yes, -y Skip all confirmation prompts
--help, -h Show this help
EOF
exit 0
;;
*)
log_error "Unknown argument: $arg"
exit 1
;;
esac
done
confirm_action() {
local prompt="$1"
if [[ "$AUTO_YES" == "true" ]]; then
log_info "Auto-confirmed (--yes): ${prompt}"
return 0
fi
printf '%s' "$prompt"
read -r confirm
[[ "$confirm" =~ ^[Yy]$ ]]
}
load_env
require_vars FEDORA_IP FEDORA_SSH_USER FEDORA_GITEA_DATA_PATH
@@ -26,9 +59,7 @@ TEARDOWN_FAILED=false
# ---------------------------------------------------------------------------
# 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
if confirm_action 'This will stop Gitea on Fedora. Continue? [y/N] '; then
# Try modern "docker compose" first, fall back to standalone
if ssh_exec FEDORA "cd '${DATA_PATH}' && docker compose down 2>/dev/null || docker-compose down"; then
log_success "Gitea container stopped and removed"
@@ -44,9 +75,7 @@ else
existing_container=$(ssh_exec FEDORA "docker ps -a --filter 'name=^/gitea$' --format '{{.ID}}'" 2>/dev/null || true)
if [[ -n "$existing_container" ]]; then
log_warn "docker-compose.yml not found, but gitea container still exists."
printf 'Force-remove gitea container directly? [y/N] '
read -r confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
if confirm_action 'Force-remove gitea container directly? [y/N] '; then
if ssh_exec FEDORA "docker rm -f gitea" >/dev/null 2>&1; then
log_success "Gitea container force-removed"
else
@@ -66,9 +95,7 @@ fi
# Only removed if no containers are still attached.
# ---------------------------------------------------------------------------
if ssh_exec FEDORA "docker network inspect gitea_net" &>/dev/null; then
printf 'Remove macvlan network gitea_net on Fedora? [y/N] '
read -r confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
if confirm_action 'Remove macvlan network gitea_net on Fedora? [y/N] '; then
if ssh_exec FEDORA "docker network rm gitea_net" >/dev/null 2>&1; then
log_success "macvlan network gitea_net removed"
else
@@ -91,9 +118,7 @@ if [[ -n "$running_container" ]]; then
log_warn "Gitea container is still running — refusing to remove data directory."
log_warn "Stop the container first, then re-run teardown to remove data."
elif 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
if confirm_action "$(printf 'Remove ALL Gitea data at %s on Fedora? This is IRREVERSIBLE. [y/N] ' "$DATA_PATH")"; then
if ssh_exec FEDORA "rm -rf '${DATA_PATH}'"; then
log_success "All Gitea data removed from Fedora"
else

View File

@@ -12,6 +12,39 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# Parse arguments
AUTO_YES=false
for arg in "$@"; do
case "$arg" in
--yes|-y) AUTO_YES=true ;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--yes, -y Skip all confirmation prompts
--help, -h Show this help
EOF
exit 0
;;
*)
log_error "Unknown argument: $arg"
exit 1
;;
esac
done
confirm_action() {
local prompt="$1"
if [[ "$AUTO_YES" == "true" ]]; then
log_info "Auto-confirmed (--yes): ${prompt}"
return 0
fi
printf '%s' "$prompt"
read -r confirm
[[ "$confirm" =~ ^[Yy]$ ]]
}
load_env
log_warn "=== Phase 3 Teardown: Runners ==="
@@ -32,9 +65,7 @@ FAILED=0
# Step 1: Remove each runner via manage_runner.sh
# manage_runner.sh handles its own safety (skips already-removed runners).
# ---------------------------------------------------------------------------
printf 'This will stop and remove all runners. Continue? [y/N] '
read -r confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
if confirm_action 'This will stop and remove all runners. Continue? [y/N] '; then
while IFS= read -r name; do
[[ -z "$name" ]] && continue
log_info "Removing runner: ${name}"

View File

@@ -11,6 +11,39 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# Parse arguments
AUTO_YES=false
for arg in "$@"; do
case "$arg" in
--yes|-y) AUTO_YES=true ;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--yes, -y Skip all confirmation prompts
--help, -h Show this help
EOF
exit 0
;;
*)
log_error "Unknown argument: $arg"
exit 1
;;
esac
done
confirm_action() {
local prompt="$1"
if [[ "$AUTO_YES" == "true" ]]; then
log_info "Auto-confirmed (--yes): ${prompt}"
return 0
fi
printf '%s' "$prompt"
read -r confirm
[[ "$confirm" =~ ^[Yy]$ ]]
}
load_env
require_vars GITEA_ADMIN_TOKEN GITEA_BACKUP_ADMIN_TOKEN \
GITEA_INTERNAL_URL GITEA_BACKUP_INTERNAL_URL \
@@ -21,9 +54,7 @@ log_warn "=== Phase 4 Teardown: Repos + Mirrors ==="
read -ra REPOS <<< "$REPO_NAMES"
printf 'This will DELETE all migrated repos and mirrors. Continue? [y/N] '
read -r confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
if ! confirm_action 'This will DELETE all migrated repos and mirrors. Continue? [y/N] '; then
log_info "Teardown cancelled"
exit 0
fi

View File

@@ -10,6 +10,39 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# Parse arguments
AUTO_YES=false
for arg in "$@"; do
case "$arg" in
--yes|-y) AUTO_YES=true ;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--yes, -y Skip all confirmation prompts
--help, -h Show this help
EOF
exit 0
;;
*)
log_error "Unknown argument: $arg"
exit 1
;;
esac
done
confirm_action() {
local prompt="$1"
if [[ "$AUTO_YES" == "true" ]]; then
log_info "Auto-confirmed (--yes): ${prompt}"
return 0
fi
printf '%s' "$prompt"
read -r confirm
[[ "$confirm" =~ ^[Yy]$ ]]
}
load_env
require_vars GITEA_ADMIN_TOKEN GITEA_INTERNAL_URL GITEA_ORG_NAME \
GITEA_ADMIN_USER \
@@ -51,9 +84,7 @@ git_with_auth() {
"$@"
}
printf 'This will remove .gitea/workflows/ from all repos. Continue? [y/N] '
read -r confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
if ! confirm_action 'This will remove .gitea/workflows/ from all repos. Continue? [y/N] '; then
log_info "Teardown cancelled"
exit 0
fi

View File

@@ -11,6 +11,39 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# Parse arguments
AUTO_YES=false
for arg in "$@"; do
case "$arg" in
--yes|-y) AUTO_YES=true ;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--yes, -y Skip all confirmation prompts
--help, -h Show this help
EOF
exit 0
;;
*)
log_error "Unknown argument: $arg"
exit 1
;;
esac
done
confirm_action() {
local prompt="$1"
if [[ "$AUTO_YES" == "true" ]]; then
log_info "Auto-confirmed (--yes): ${prompt}"
return 0
fi
printf '%s' "$prompt"
read -r confirm
[[ "$confirm" =~ ^[Yy]$ ]]
}
load_env
require_vars GITEA_ADMIN_TOKEN GITEA_INTERNAL_URL GITEA_ORG_NAME \
GITHUB_USERNAME GITHUB_TOKEN \
@@ -20,9 +53,7 @@ log_warn "=== Phase 6 Teardown: Push Mirrors ==="
read -ra REPOS <<< "$REPO_NAMES"
printf 'This will remove all push mirror configurations. Continue? [y/N] '
read -r confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
if ! confirm_action 'This will remove all push mirror configurations. Continue? [y/N] '; then
log_info "Teardown cancelled"
exit 0
fi

View File

@@ -10,6 +10,39 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# Parse arguments
AUTO_YES=false
for arg in "$@"; do
case "$arg" in
--yes|-y) AUTO_YES=true ;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--yes, -y Skip all confirmation prompts
--help, -h Show this help
EOF
exit 0
;;
*)
log_error "Unknown argument: $arg"
exit 1
;;
esac
done
confirm_action() {
local prompt="$1"
if [[ "$AUTO_YES" == "true" ]]; then
log_info "Auto-confirmed (--yes): ${prompt}"
return 0
fi
printf '%s' "$prompt"
read -r confirm
[[ "$confirm" =~ ^[Yy]$ ]]
}
load_env
require_vars GITEA_ADMIN_TOKEN GITEA_INTERNAL_URL GITEA_ORG_NAME \
REPO_NAMES PROTECTED_BRANCH
@@ -18,9 +51,7 @@ log_warn "=== Phase 7 Teardown: Branch Protection ==="
read -ra REPOS <<< "$REPO_NAMES"
printf 'This will remove branch protection for "%s" on all repos. Continue? [y/N] ' "$PROTECTED_BRANCH"
read -r confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
if ! confirm_action "$(printf 'This will remove branch protection for \"%s\" on all repos. Continue? [y/N] ' "$PROTECTED_BRANCH")"; then
log_info "Teardown cancelled"
exit 0
fi

View File

@@ -12,6 +12,39 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# Parse arguments
AUTO_YES=false
for arg in "$@"; do
case "$arg" in
--yes|-y) AUTO_YES=true ;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--yes, -y Skip all confirmation prompts
--help, -h Show this help
EOF
exit 0
;;
*)
log_error "Unknown argument: $arg"
exit 1
;;
esac
done
confirm_action() {
local prompt="$1"
if [[ "$AUTO_YES" == "true" ]]; then
log_info "Auto-confirmed (--yes): ${prompt}"
return 0
fi
printf '%s' "$prompt"
read -r confirm
[[ "$confirm" =~ ^[Yy]$ ]]
}
load_env
require_vars UNRAID_IP UNRAID_SSH_USER \
GITEA_DOMAIN CADDY_DATA_PATH \
@@ -36,9 +69,7 @@ github_pages_http_code() {
# ---------------------------------------------------------------------------
CONTAINER_STATUS=$(ssh_exec UNRAID "docker ps --filter name=caddy --format '{{.Status}}'" 2>/dev/null || true)
if [[ "$CONTAINER_STATUS" == *"Up"* ]]; then
printf 'Stop and remove Caddy container? [y/N] '
read -r confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
if confirm_action 'Stop and remove Caddy container? [y/N] '; then
ssh_exec UNRAID "cd '${CADDY_DATA_PATH}' && docker compose down 2>/dev/null || docker-compose down"
log_success "Caddy container stopped and removed"
else
@@ -60,9 +91,7 @@ fi
# Step 2: Optionally remove Caddy data (certs, config)
# ---------------------------------------------------------------------------
if ssh_exec UNRAID "test -d '${CADDY_DATA_PATH}/data'" 2>/dev/null; then
printf 'Remove Caddy TLS data (certificates) for %s? [y/N] ' "$GITEA_DOMAIN"
read -r confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
if confirm_action "$(printf 'Remove Caddy TLS data (certificates) for %s? [y/N] ' "$GITEA_DOMAIN")"; then
ssh_exec UNRAID "rm -rf '${CADDY_DATA_PATH}/data' '${CADDY_DATA_PATH}/config'"
log_success "Caddy TLS data removed"
else
@@ -76,9 +105,7 @@ fi
# Fallback path: if snapshot is missing, restore description from "— was: ..."
# and use legacy defaults for homepage/wiki/projects.
# ---------------------------------------------------------------------------
printf 'Restore GitHub repo settings (description/homepage/wiki/projects/pages)? [y/N] '
read -r confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
if confirm_action 'Restore GitHub repo settings (description/homepage/wiki/projects/pages)? [y/N] '; then
STATE_AVAILABLE=false
if [[ -f "$PHASE8_STATE_FILE" ]]; then
STATE_AVAILABLE=true

View File

@@ -10,6 +10,39 @@ set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "${SCRIPT_DIR}/lib/common.sh"
# Parse arguments
AUTO_YES=false
for arg in "$@"; do
case "$arg" in
--yes|-y) AUTO_YES=true ;;
--help|-h)
cat <<EOF
Usage: $(basename "$0") [options]
Options:
--yes, -y Skip all confirmation prompts
--help, -h Show this help
EOF
exit 0
;;
*)
log_error "Unknown argument: $arg"
exit 1
;;
esac
done
confirm_action() {
local prompt="$1"
if [[ "$AUTO_YES" == "true" ]]; then
log_info "Auto-confirmed (--yes): ${prompt}"
return 0
fi
printf '%s' "$prompt"
read -r confirm
[[ "$confirm" =~ ^[Yy]$ ]]
}
load_env
require_vars GITEA_ADMIN_TOKEN GITEA_INTERNAL_URL GITEA_ORG_NAME \
GITEA_ADMIN_USER \
@@ -52,9 +85,7 @@ git_with_auth() {
"$@"
}
printf 'This will remove security-scan.yml from all repos. Continue? [y/N] '
read -r confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
if ! confirm_action 'This will remove security-scan.yml from all repos. Continue? [y/N] '; then
log_info "Teardown cancelled"
exit 0
fi

View File

@@ -70,12 +70,6 @@ if [[ "$AUTO_YES" == "false" ]]; then
fi
fi
# ---------------------------------------------------------------------------
# Export YES=true so individual teardown scripts skip their own prompts
# when --yes is passed. Each teardown script checks for interactive input,
# but when called from here with --yes, we pipe 'y' to them instead.
# ---------------------------------------------------------------------------
# Teardown scripts in reverse order (9 → 1)
# Each entry: phase_num|script_path
TEARDOWNS=(
@@ -105,12 +99,8 @@ for entry in "${TEARDOWNS[@]}"; do
log_info ">>> Tearing down Phase ${phase_num}..."
if [[ "$AUTO_YES" == "true" ]]; then
# Feed unlimited 'y' responses via process substitution.
# A pipeline (yes | script) would break under pipefail: when the script
# finishes and closes stdin, `yes` gets SIGPIPE (exit 141), making the
# pipeline report failure even though the teardown succeeded.
# Process substitution avoids this — only the script's exit code matters.
if "${SCRIPT_DIR}/${script}" < <(yes); then
# Pass --yes through to each teardown script so prompts are skipped.
if "${SCRIPT_DIR}/${script}" --yes; then
PASS=$((PASS + 1))
else
log_warn "Phase ${phase_num} teardown had issues (continuing)"