#!/bin/bash # --------------------------------------------------------------------- # pvesnap - Deinstallation # # ./uninstall.sh Programm und Dienst entfernen, # Konfiguration und Zustand bleiben erhalten # ./uninstall.sh --purge zusaetzlich /etc/pvesnap und /var/lib/pvesnap # entfernen # # Bereits angelegte Snapshots werden NIE angeruehrt. # --------------------------------------------------------------------- set -euo pipefail LIB_DIR="/usr/lib/pvesnap" BIN="/usr/local/bin/pvesnap" CONF_DIR="/etc/pvesnap" STATE_DIR="/var/lib/pvesnap" DOC_DIR="/usr/share/doc/pvesnap" UNIT="/etc/systemd/system/pvesnap.service" PURGE=0 YES=0 for arg in "$@"; do case "$arg" in --purge) PURGE=1 ;; -y|--yes) YES=1 ;; -h|--help) sed -n '2,11p' "$0" | sed 's/^#[[:space:]]\{0,1\}//'; exit 0 ;; *) echo "Unbekannte Option: $arg" >&2; exit 1 ;; esac done info() { printf '\033[1;32m==>\033[0m %s\n' "$*"; } warn() { printf '\033[1;33m==>\033[0m %s\n' "$*" >&2; } fail() { printf '\033[1;31m==>\033[0m %s\n' "$*" >&2; exit 1; } [ "$(id -u)" -eq 0 ] || fail "Bitte als root ausfuehren (sudo ./uninstall.sh)." if [ "$YES" -eq 0 ]; then if [ "$PURGE" -eq 1 ]; then printf 'pvesnap inklusive Konfiguration und Zustand entfernen? [j/N] ' else printf 'pvesnap entfernen (Konfiguration bleibt erhalten)? [j/N] ' fi read -r answer case "$answer" in j|J|y|Y) ;; *) echo "Abgebrochen."; exit 0 ;; esac fi if systemctl list-unit-files 2>/dev/null | grep -q '^pvesnap\.service'; then info "Stoppe und deaktiviere Dienst" systemctl stop pvesnap.service 2>/dev/null || true systemctl disable pvesnap.service 2>/dev/null || true fi if [ -f "$UNIT" ]; then info "Entferne $UNIT" rm -f "$UNIT" fi systemctl daemon-reload 2>/dev/null || true systemctl reset-failed pvesnap.service 2>/dev/null || true if [ -e "$BIN" ]; then info "Entferne $BIN" rm -f "$BIN" fi if [ -d "$LIB_DIR" ]; then info "Entferne $LIB_DIR" rm -rf "$LIB_DIR" fi rm -rf "$DOC_DIR" rm -f /run/pvesnap.lock /run/pvesnap.lock.daemon if [ "$PURGE" -eq 1 ]; then info "Entferne Konfiguration und Zustand" rm -rf "$CONF_DIR" "$STATE_DIR" else warn "Behalten: $CONF_DIR und $STATE_DIR (mit --purge ebenfalls entfernen)" fi cat < / qm delsnapshot pct listsnapshot / pct delsnapshot EOF