#!/bin/bash # ============================================================================= # plugin/sbin/podman-uninstall-cleanup.sh # # "Beim Entfernen sauber aufräumen" — run by plugin/podman.plg's block when the plugin is uninstalled via Unraid's Plugins # page. Two-tier cleanup, matching docs/ARCHITECTURE.md section 3.2 / # section 17: # # ALWAYS removed (installed software, safe to regenerate): # - running containers/service stopped cleanly # - runtime config under /etc/containers, /var/run/podman # - staged helper scripts, templates, WebUI files, event hooks # # NOT applicable: this project has no /boot/config/go entry to clean up # in the first place — it hooks the official Unraid plugin event # mechanism (/usr/local/emhttp/plugins/podman/event/*, see # plugin/event/disks_mounted's header comment) instead of editing go, # so removepkg-ing the unraid-podman package (done by podman.plg right # after this script runs) already removes those hooks along with # everything else under /usr/local/emhttp/plugins/podman/. # # PRESERVED BY DEFAULT (user data — see docs/INSTALL.md "Uninstallation"): # - /boot/config/plugins/podman/ (settings, autostart list, backups) # - $STORAGE_PATH (podman.img — every image/container/volume the user # has) # # Full data removal is opt-in only, via: # podman-uninstall-cleanup.sh --purge-data # never the default, and never triggered automatically — deleting a user's # containers/images without an explicit, separate confirmation is exactly # the kind of destructive-by-surprise behavior this project avoids (see # docs/ARCHITECTURE.md "Nicht-Ziele" around data safety). # ============================================================================= set -u SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # shellcheck source=./podman-common.sh . "$SCRIPT_DIR/podman-common.sh" PURGE_DATA=0 [ "${1:-}" = "--purge-data" ] && PURGE_DATA=1 podman_log "uninstall: starting cleanup (purge-data=$PURGE_DATA)" # ----------------------------------------------------------------------------- # 1. Stop podman cleanly if it's running, so containers shut down properly # and the storage loopback is unmounted before we remove anything else. # ----------------------------------------------------------------------------- if [ -x /etc/rc.d/rc.podman ]; then podman_log "uninstall: stopping podman" /etc/rc.d/rc.podman stop || podman_log_error "uninstall: rc.podman stop reported an error (continuing cleanup anyway)" fi # ----------------------------------------------------------------------------- # 2. Remove runtime state (RAM-root anyway, but tidy up now rather than # waiting for the next reboot to implicitly clear it). # ----------------------------------------------------------------------------- podman_log "uninstall: removing runtime state" rm -rf "$PODMAN_ETC_DIR" "$PODMAN_RUN_DIR" # ----------------------------------------------------------------------------- # 3. Remove staged files this plugin installed outside of package-managed # paths. This is technically redundant with podman.plg's removepkg of # the unraid-podman package that immediately follows this script (see # that package's manifest — it owns exactly these paths), but doing it # explicitly here too means this script is also safe to run manually as # a standalone repair tool without relying on removepkg bookkeeping. # ----------------------------------------------------------------------------- podman_log "uninstall: removing plugin scaffolding" rm -rf /usr/local/share/unraid-podman rm -rf /usr/local/emhttp/plugins/podman rm -f /etc/rc.d/rc.podman # ----------------------------------------------------------------------------- # 4. User data — preserved unless --purge-data was explicitly passed. # ----------------------------------------------------------------------------- if [ "$PURGE_DATA" -eq 1 ]; then podman_load_cfg podman_log "uninstall: --purge-data given, removing user data" if [ -n "${STORAGE_PATH:-}" ] && [ -d "$STORAGE_PATH" ]; then podman_log "uninstall: removing $STORAGE_PATH (images, containers, volumes, logs)" rm -rf "${STORAGE_PATH:?}" fi podman_log "uninstall: removing $PODMAN_BOOT_DIR (settings, autostart, backups)" rm -rf "${PODMAN_BOOT_DIR:?}" else podman_log "uninstall: preserving $PODMAN_BOOT_DIR and podman's storage path (pass --purge-data to remove them too)" fi podman_log "uninstall: cleanup complete"