feat: add --yes support to teardown scripts
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user