summaryrefslogtreecommitdiff
path: root/src/chroot-tools/chcleanup
diff options
context:
space:
mode:
authorNicolás Reynolds <apoyosis@correo.inta.gob.ar>2012-11-07 15:06:55 -0300
committerNicolás Reynolds <apoyosis@correo.inta.gob.ar>2012-11-07 15:06:55 -0300
commit73b813613aa08646515f4e06c71503b18125cec3 (patch)
tree5b98b01f1c331692e2dcae4fd4f6fb4e4a7064df /src/chroot-tools/chcleanup
parent6c14fad1750b4342b5b283e0851c00e3c074a15c (diff)
parent040111e9d8419456255816600784a496febd57b0 (diff)
Merge branch 'master' of git://gitorious.org/parabola/libretools
Diffstat (limited to 'src/chroot-tools/chcleanup')
-rwxr-xr-xsrc/chroot-tools/chcleanup57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/chroot-tools/chcleanup b/src/chroot-tools/chcleanup
new file mode 100755
index 0000000..17c1f02
--- /dev/null
+++ b/src/chroot-tools/chcleanup
@@ -0,0 +1,57 @@
+#!/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
+DRYRUN=${DRYRUN:-false}
+
+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 we're running makepkg
+if [ -f PKGBUILD ]; then
+ source PKGBUILD || true
+
+ check=(${depends[@]} ${makedepends[@]} ${checkdepends[@]})
+
+fi
+
+# 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) \
+ <(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[@]}
+
+# Cleanup
+${DRYRUN} || rm -fr ${TMPDIR}
+
+exit $?