#!/bin/bash
# ARIA Docker Cleanup
#
# Standard:  docker builder prune + image prune (sicher, loescht keine Volumes)
# --full:    Volle Reinigung inkl. --volumes (Vorsicht bei ungenutzten Volumes!)
#
# Usage:
#   ./cleanup.sh           # sicherer Cleanup
#   ./cleanup.sh --full    # aggressiver Cleanup (inkl. Volumes)

set -e

FULL=0
for arg in "$@"; do
  case "$arg" in
    --full|-f) FULL=1 ;;
    -h|--help)
      grep '^#' "$0" | sed 's/^# \{0,1\}//'
      exit 0
      ;;
  esac
done

echo "── Docker Speicher VOR Cleanup ───────────────────"
docker system df
echo

if [ "$FULL" = "1" ]; then
  echo ">>> VOLLE Reinigung (inkl. ungenutzter Volumes)"
  read -p "Wirklich? [y/N] " -n 1 -r REPLY
  echo
  [[ ! $REPLY =~ ^[Yy]$ ]] && { echo "Abgebrochen."; exit 0; }
  docker system prune -a --volumes -f
else
  echo ">>> Sicherer Cleanup (Build-Cache + ungenutzte Images)"
  docker builder prune -a -f
  docker image prune -a -f
fi

echo
echo "── Docker Speicher NACH Cleanup ──────────────────"
docker system df
echo
df -h / | head -2
