diff options
author | Nicolás Reynolds <fauno@kiwwwi.com.ar> | 2012-09-22 18:47:21 -0300 |
---|---|---|
committer | Nicolás Reynolds <fauno@kiwwwi.com.ar> | 2012-09-22 18:47:21 -0300 |
commit | a323ff09d756dd06a559586467c84dbe78069060 (patch) | |
tree | 72ef17c8ece9b29e83634340cd78a5e3cba4ac10 /chcleanup | |
parent | cddf27b728fd46157685b3791245fed53393cb18 (diff) |
Deprecate clean-pacman in favor of smart chcleanup
Chcleanup compares the currently installed packages with a clean system list of
packages + the package dependencies and removes the leftovers.
Treepkg runs it as pre-build hook, so FULLBUILDCMD finds only the needed
dependencies.
Diffstat (limited to 'chcleanup')
-rwxr-xr-x | chcleanup | 44 |
1 files changed, 41 insertions, 3 deletions
@@ -1,11 +1,49 @@ #!/bin/bash +# (c) Nicolás Reynolds <fauno@parabola.nu> +# Released under GPLv3 +# +# Performs chroot cleanup smartly, it only removes the unneeded packages or +# leaves you with a cleansystem +# +# See: HOOKPREBUILD + +set -e [ ! -f /etc/libretools.d/cleansystem ] && exit 1 +[ ! -d "${DB:-/var/lib/libretools/clean}"/sync ] && exit 1 + +source $(dirname $0)/libremessages + +msg "Cleaning chroot..." + +cleanup_log=/tmp/libretools-cleanup.log +touch ${cleanup_log} + +# If we're running makepkg +if [ -f PKGBUILD ]; then + source PKGBUILD || true + +# Update the cleansystem database + sudo pacman -b "${BD:-/var/lib/libretools/clean}" -Sy +# Get the full list of packages needed by dependencies + sudo pacman -b "${BD:-/var/lib/libretools/clean}" \ + -Sp \ + --print-format "%n" \ + ${depends[@]} ${makedepends[@]} ${checkdepends[@]} \ + >${cleanup_log} +fi + +# Diff installed packages against a clean chroot and needed packages, +# then remove leftovers +packages=($(comm -23 <(pacman -Qq | sort) \ + <(cat /etc/libretools.d/cleansystem ${cleanup_log} | sort -u) + )) -packages=($(comm -23 <(pacman -Qq | sort) <(sort /etc/libretools.d/cleansystem))) +[ ${#packages[@]} -eq 0 ] && exit 0 -echo "Removing: ${packages[@]}" +msg2 "Removing ${#packages[@]} packages: ${packages[@]}" -sudo pacman --noconfirm -Rcs ${packages[@]} +# Only remove leftovers, -Rcs removes too much +sudo pacman --noconfirm -Rn ${packages[@]} exit $? |