diff options
Diffstat (limited to 'src/chroot-tools/chcleanup')
-rwxr-xr-x | src/chroot-tools/chcleanup | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/chroot-tools/chcleanup b/src/chroot-tools/chcleanup index 17c1f02..821c572 100755 --- a/src/chroot-tools/chcleanup +++ b/src/chroot-tools/chcleanup @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash -eE # (c) Nicolás Reynolds <fauno@parabola.nu> # Released under GPLv3 # @@ -7,51 +7,51 @@ # # See: HOOKPREBUILD -set -e DRYRUN=${DRYRUN:-false} +source "$(which libremessages)" -source /etc/makepkg.conf -source /etc/libretools.conf -source ${HOME}/.makepkg.conf 2>/dev/null|| true - -msg "Cleaning chroot..." - -TMPDIR="$(mktemp -d /tmp/$(basename $0)-XXXXX)" -cleanup_log="${TMPDIR}"/libretools-cleanup.log - -cp -a /var/lib/pacman/sync "${TMPDIR}/" -touch ${cleanup_log} +if [[ ! -f /.arch-chroot ]] && ! ${DRYRUN}; then + error "(chcleanup): Must be run inside of a chroot" + exit 1 +fi +source /etc/libretools.d/chroot.conf # If we're running makepkg if [ -f PKGBUILD ]; then - source PKGBUILD || true + source PKGBUILD + CHROOTEXTRAPKG+=("${depends[@]}" + "${makedepends[@]}" + "${checkdepends[@]}") +fi - check=(${depends[@]} ${makedepends[@]} ${checkdepends[@]}) +msg "Cleaning chroot..." -fi +TEMPDIR="$(mktemp --tmpdir -d $(basename $0).XXXXX)" +cp -a /var/lib/pacman/sync "${TEMPDIR}/" +cleanup_log="${TEMPDIR}"/libretools-cleanup.log # 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} +pacman -b "${TEMPDIR}" \ + -Sp --print-format "%n" \ + base base-devel sudo "${CHROOTEXTRAPKG[@]}" \ + >"${cleanup_log}" # Diff installed packages against a clean chroot then remove leftovers -packages=($(comm -23 <(pacman -Qq | sort) \ - <(sort -u ${cleanup_log}))) - -[ ${#packages[@]} -eq 0 ] && exit 0 - -msg2 "Removing %d packages" ${#packages[@]} - -# Only remove leftovers, -Rcs removes too much -${DRYRUN} || sudo pacman --noconfirm -Rn ${packages[@]} -${DRYRUN} && echo ${packages[@]} - +packages=($(comm -23 <(pacman -Qq | sort -u) \ + <(sort -u "${cleanup_log}"))) + +RET=0 +if [[ ${#packages[@]} != 0 ]]; then + msg2 "Removing %d packages" ${#packages[@]} + + if ${DRYRUN}; then + echo "${packages[@]}" + else + # Only remove leftovers, -Rcs removes too much + pacman --noconfirm -Rn "${packages[@]}" || RET=$? + fi +fi # Cleanup -${DRYRUN} || rm -fr ${TMPDIR} +rm -rf "${TEMPDIR}" -exit $? +exit $RET |