diff options
Diffstat (limited to 'chcleanup')
-rwxr-xr-x | chcleanup | 41 |
1 files changed, 19 insertions, 22 deletions
@@ -9,16 +9,16 @@ 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 /etc/libretools.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,33 +27,30 @@ 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 msg2 "Removing %d packages" ${#packages[@]} # Only remove leftovers, -Rcs removes too much -sudo pacman --noconfirm -Rn ${packages[@]} +${DRYRUN} || sudo pacman --noconfirm -Rn ${packages[@]} +${DRYRUN} && echo ${packages[@]} # Cleanup -rm -f ${cleanup_log} +${DRYRUN} || rm -fr ${TMPDIR} exit $? |