Projektarbeit-MYP/cleanup.sh

115 lines
3.3 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 🧹 MYP - Manage your Printer (Hauptbereinigungsskript)
# Weiterleitung an das optimierte Infrastructure-Bereinigungsskript
set -euo pipefail
# Farbdefinitionen für bessere Ausgabe
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[1;33m'
readonly BLUE='\033[0;34m'
readonly MAGENTA='\033[0;35m'
readonly CYAN='\033[0;36m'
readonly WHITE='\033[1;37m'
readonly NC='\033[0m' # No Color
# Logging-Funktionen
log_info() { echo -e "${CYAN} $1${NC}"; }
log_success() { echo -e "${GREEN}$1${NC}"; }
log_warning() { echo -e "${YELLOW}⚠️ $1${NC}"; }
log_error() { echo -e "${RED}$1${NC}"; }
log_header() { echo -e "${MAGENTA}$1${NC}"; }
# Standard-Parameter
FORCE_MODE=false
ALL_MODE=false
SHOW_HELP=false
# Hilfe-Funktion
show_help() {
log_header "🧹 MYP - Manage your Printer (Bereinigung)"
log_header "═══════════════════════════════════════════"
echo
log_info "📖 Verwendung:"
echo " ./cleanup.sh [Optionen]"
echo
log_info "⚙️ Optionen:"
echo " -f, --force - Bereinigung ohne Bestätigung durchführen"
echo " -a, --all - Vollständige Bereinigung (inkl. Volumes)"
echo " -h, --help - Diese Hilfe anzeigen"
echo
log_info "📚 Beispiele:"
echo " ./cleanup.sh # Interaktive Bereinigung"
echo " ./cleanup.sh --force # Automatische Bereinigung"
echo " ./cleanup.sh --all --force # Vollständige Bereinigung"
echo
}
# Parameter-Parsing
while [[ $# -gt 0 ]]; do
case $1 in
-f|--force)
FORCE_MODE=true
shift
;;
-a|--all)
ALL_MODE=true
shift
;;
-h|--help)
SHOW_HELP=true
shift
;;
*)
log_error "Unbekannter Parameter: $1"
echo "Verwenden Sie --help für Hilfe."
exit 1
;;
esac
done
# Hilfe anzeigen
if [[ "$SHOW_HELP" == true ]]; then
show_help
exit 0
fi
# Header anzeigen
log_header "🧹 MYP - Manage your Printer (Bereinigung)"
log_header "═══════════════════════════════════════════"
# Prüfe ob Infrastructure-Skript existiert
INFRA_SCRIPT="./infrastructure/scripts/cleanup.sh"
if [[ ! -f "$INFRA_SCRIPT" ]]; then
log_error "❌ Infrastructure-Bereinigungsskript nicht gefunden: $INFRA_SCRIPT"
log_error " Bitte stellen Sie sicher, dass die Projektstruktur vollständig ist."
exit 1
fi
# Prüfe Ausführungsrechte
if [[ ! -x "$INFRA_SCRIPT" ]]; then
log_warning "⚠️ Setze Ausführungsrechte für Infrastructure-Skript..."
chmod +x "$INFRA_SCRIPT"
fi
# Parameter für Infrastructure-Skript vorbereiten
INFRA_PARAMS=()
if [[ "$FORCE_MODE" == true ]]; then
INFRA_PARAMS+=("--force")
fi
if [[ "$ALL_MODE" == true ]]; then
INFRA_PARAMS+=("--all")
fi
# Weiterleitung an Infrastructure-Skript
log_info "🔄 Weiterleitung an Infrastructure-Bereinigungsskript..."
if "${INFRA_SCRIPT}" "${INFRA_PARAMS[@]}"; then
log_success "🎉 Bereinigung erfolgreich abgeschlossen!"
exit 0
else
EXIT_CODE=$?
log_error "❌ Bereinigung fehlgeschlagen (Exit Code: $EXIT_CODE)"
exit $EXIT_CODE
fi