#!/bin/bash
################################################################################
# Pavon Cleanup Status Checker
# Quick script to check deletion progress
################################################################################

echo "Checking Pavon cleanup status..."
echo ""

ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@172.16.1.33 '
echo "==================================================================="
echo "PAVON CLEANUP STATUS"
echo "==================================================================="
echo ""

# Check if cleanup is running
if ps aux | grep -q "[p]avon_cleanup.sh"; then
    echo "[RUNNING] Cleanup process is active"
    echo ""

    # Count deleted files
    deleted=$(grep -c "Deleted:" /root/cleanup_logs/cleanup_*.log 2>/dev/null | awk "{sum+=\$1} END {print sum}")
    echo "Files deleted: $deleted / 184,120"
    percent=$(echo "scale=1; $deleted * 100 / 184120" | bc)
    echo "Progress: $percent%"
    echo ""

    # Show current disk usage
    echo "Current disk usage:"
    df -h /mnt/user | tail -1
    echo ""

    # Show recent activity
    echo "Recent deletions:"
    tail -5 $(ls -t /root/cleanup_logs/cleanup_*.log | head -1)

else
    echo "[COMPLETE] Cleanup process finished"
    echo ""

    # Show final results
    latest_log=$(ls -t /root/cleanup_logs/cleanup_*.log | head -1)
    echo "Final log: $latest_log"
    echo ""

    # Count total deleted
    deleted=$(grep -c "Deleted:" $latest_log 2>/dev/null)
    echo "Total files deleted: $deleted"
    echo ""

    # Show final disk usage
    echo "Final disk usage:"
    df -h /mnt/user | tail -1
    echo ""

    # Check for errors
    errors=$(grep -c "Failed:" $latest_log 2>/dev/null)
    echo "Failed deletions: $errors"
fi

echo "==================================================================="
' 2>&1
