From 62c9e0f2bbeb5ca8594d635d4000ccb7442ef137 Mon Sep 17 00:00:00 2001 From: S Date: Mon, 2 Mar 2026 11:32:01 -0500 Subject: [PATCH] feat: add --yes support to teardown scripts --- phase1_gitea_unraid.sh | 11 ---------- phase1_teardown.sh | 45 ++++++++++++++++++++++++++++++-------- phase2_teardown.sh | 49 +++++++++++++++++++++++++++++++----------- phase3_teardown.sh | 37 ++++++++++++++++++++++++++++--- phase4_teardown.sh | 37 ++++++++++++++++++++++++++++--- phase5_teardown.sh | 37 ++++++++++++++++++++++++++++--- phase6_teardown.sh | 37 ++++++++++++++++++++++++++++--- phase7_teardown.sh | 37 ++++++++++++++++++++++++++++--- phase8_teardown.sh | 45 ++++++++++++++++++++++++++++++-------- phase9_teardown.sh | 37 ++++++++++++++++++++++++++++--- teardown_all.sh | 14 ++---------- 11 files changed, 315 insertions(+), 71 deletions(-) diff --git a/phase1_gitea_unraid.sh b/phase1_gitea_unraid.sh index a09e48f..1d3e105 100755 --- a/phase1_gitea_unraid.sh +++ b/phase1_gitea_unraid.sh @@ -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 # --------------------------------------------------------------------------- diff --git a/phase1_teardown.sh b/phase1_teardown.sh index 56ac508..01eff5b 100755 --- a/phase1_teardown.sh +++ b/phase1_teardown.sh @@ -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 </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 diff --git a/phase2_teardown.sh b/phase2_teardown.sh index 2c68a0f..308a9f7 100755 --- a/phase2_teardown.sh +++ b/phase2_teardown.sh @@ -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 </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 diff --git a/phase3_teardown.sh b/phase3_teardown.sh index 5ece662..f55312f 100755 --- a/phase3_teardown.sh +++ b/phase3_teardown.sh @@ -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 </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 diff --git a/phase9_teardown.sh b/phase9_teardown.sh index 2be6035..1c86739 100755 --- a/phase9_teardown.sh +++ b/phase9_teardown.sh @@ -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 <>> 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)"