diff --git a/clean.sh b/clean.sh index efcab13..01867d5 100755 --- a/clean.sh +++ b/clean.sh @@ -2,12 +2,20 @@ # Arch Linux cleanup + update script set -euo pipefail +# Function to get used space in kilobytes +get_used_space() { + df / --output=used | tail -1 +} + +echo "==> Calculating initial disk usage..." +PRE_USED=$(get_used_space) + echo "==> Cleaning leftover downloads..." sudo rm -rf /var/cache/pacman/pkg/*.part sudo rm -rf /var/cache/pacman/pkg/download-* echo "==> Cleaning package cache..." -yay -Sc --noconfirm +yay -Scc --noconfirm echo "==> Cleaning user cache..." sudo rm -rf ~/.cache/* @@ -16,21 +24,13 @@ echo "==> Updating packages..." yay -Syu --noconfirm echo "==> Removing orphaned dependencies..." -yay -Yc --noconfirm +if [[ -n $(pacman -Qdtq) ]]; then + yay -Yc --noconfirm +fi echo "==> Checking for broken packages..." yay -Dk -echo "==> Cleaning leftover downloads..." -sudo rm -rf /var/cache/pacman/pkg/*.part -sudo rm -rf /var/cache/pacman/pkg/download-* - -echo "==> Cleaning package cache..." -yay -Sc --noconfirm - -echo "==> Cleaning user cache..." -sudo rm -rf ~/.cache/* - echo "==> Emptying trash..." sudo rm -rf ~/.local/share/Trash/files/* sudo rm -rf ~/.local/share/Trash/info/* @@ -38,4 +38,22 @@ sudo rm -rf ~/.local/share/Trash/info/* echo "==> Cleaning system logs..." sudo journalctl --vacuum-time=7d +echo "==> Calculating final disk usage..." +POST_USED=$(get_used_space) + +# Calculate difference +DIFF=$((PRE_USED - POST_USED)) + echo "==> Done." + +if [ "$DIFF" -gt 0 ]; then + # Convert KB to human readable format + CLEANED=$(numfmt --from-unit=1024 --to=iec-i --suffix=B "$DIFF") + echo "Successfully cleared $CLEANED of disk space." +elif [ "$DIFF" -lt 0 ]; then + # If updates were larger than the cleanup + ADDED=$(numfmt --from-unit=1024 --to=iec-i --suffix=B "${DIFF#-}") + echo "Cleanup finished, but system size increased by $ADDED due to updates." +else + echo "Cleanup finished. No change in disk usage." +fi \ No newline at end of file