diff --git a/scripts/felhom-wipe.sh b/scripts/felhom-wipe.sh index 65cf078..90b32cf 100644 --- a/scripts/felhom-wipe.sh +++ b/scripts/felhom-wipe.sh @@ -258,7 +258,7 @@ print_plan() { local bind_target bind_target=$(grep -E "^/mnt/\.felhom-raw/${label}/" /etc/fstab 2>/dev/null | awk '{print $2}' | head -1 || true) if [ -n "$bind_target" ]; then - echo -e " ${RED}umount${NC} ${bind_target} (bind) → ${rmp} (raw)" + echo -e " ${RED}umount + rmdir${NC} ${bind_target} (bind) → ${rmp} (raw)" else echo -e " ${RED}umount${NC} ${rmp} (raw, no bind found)" fi @@ -311,8 +311,9 @@ cleanup_raw_mounts() { info "Cleaning up raw helper mounts (/mnt/.felhom-raw/)..." # 1. Unmount bind mounts whose source is inside .felhom-raw (field 1 matches) + # Collect targets first so we can rmdir them after unmounting. + local bind_targets="" if [ -f /etc/fstab ]; then - local bind_targets bind_targets=$(grep -E '^/mnt/\.felhom-raw/' /etc/fstab | awk '{print $2}' || true) for mp in $bind_targets; do if mountpoint -q "$mp" 2>/dev/null; then @@ -336,8 +337,17 @@ cleanup_raw_mounts() { sed -i '\|\.felhom-raw|d' /etc/fstab && info " Removed .felhom-raw entries from /etc/fstab" fi - # 4. Remove directory — safe now that mounts are gone + # 4. Remove /mnt/.felhom-raw/ — safe now that mounts are gone rm -rf /mnt/.felhom-raw && info " Removed: /mnt/.felhom-raw/" + + # 5. Remove the now-empty bind target directories (e.g. /mnt/hdd_1). + # Use rmdir so we only remove them if truly empty — never touch user data. + for mp in $bind_targets; do + if [ -d "$mp" ]; then + rmdir "$mp" 2>/dev/null && info " Removed mount point: $mp" \ + || warn " Could not remove (not empty?): $mp" + fi + done } # --- Wipe Functions ---