From 362ec9e880e784ec9bc2858c635b0279e52af82d Mon Sep 17 00:00:00 2001 From: Nicolás Reynolds Date: Mon, 5 Nov 2012 16:02:07 -0300 Subject: Be even smarter Only use one pacman call by getting repo.db files from the local cache. Adds a new libretools.conf array for getting extra packages (other than the base system): CHROOTEXTRAPKGS. --- chcleanup | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'chcleanup') diff --git a/chcleanup b/chcleanup index b5f631c..e732b8c 100755 --- a/chcleanup +++ b/chcleanup @@ -9,16 +9,17 @@ set -e -[ ! -f /etc/libretools.d/cleansystem ] && exit 1 -[ ! -d "${DB:-/var/lib/libretools/clean}"/sync ] && exit 1 - source $(dirname $0)/libremessages source /etc/makepkg.conf source ${HOME}/.makepkg.conf 2>/dev/null|| true msg "Cleaning chroot..." -cleanup_log=/tmp/libretools-cleanup.log + +TMPDIR="$(mktemp -d /tmp/$(basename $0)-XXXXX)" +cleanup_log="${TMPDIR}"/libretools-cleanup.log + +cp -a /var/lib/pacman/sync "${TMPDIR}/" touch ${cleanup_log} # If we're running makepkg @@ -27,24 +28,20 @@ if [ -f PKGBUILD ]; then check=(${depends[@]} ${makedepends[@]} ${checkdepends[@]}) - if [ ${#check[@]} -ne 0 ]; then - -# 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" \ - ${check[@]} \ - >${cleanup_log} - fi fi -# Diff installed packages against a clean chroot and needed packages, -# then remove leftovers +# Get the full list of packages needed by dependencies, including the base system +sudo pacman -b "${TMPDIR}" \ + -Sp \ + --print-format "%n" \ + base base-devel sudo \ + ${CHROOTEXTRAPKG[@]} \ + ${check[@]} \ + >${cleanup_log} + +# Diff installed packages against a clean chroot then remove leftovers packages=($(comm -23 <(pacman -Qq | sort) \ - <(cat /etc/libretools.d/cleansystem ${cleanup_log} | sort -u) - )) + <(sort -u ${cleanup_log}))) [ ${#packages[@]} -eq 0 ] && exit 0 @@ -54,6 +51,6 @@ msg2 "Removing %d packages" ${#packages[@]} sudo pacman --noconfirm -Rn ${packages[@]} # Cleanup -rm -f ${cleanup_log} +rm -fr ${TMPDIR} exit $? -- cgit v1.2.3-54-g00ecf