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

@@ -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