summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@kiwwwi.com.ar>2012-09-22 04:26:38 -0300
committerNicolás Reynolds <fauno@kiwwwi.com.ar>2012-09-22 04:26:38 -0300
commit9ab4d557b3294c61bdee3978be50f59c63b71c37 (patch)
treea84a37042afbdb9d6fe7147a7ffc7c737f2c42b7
parentd469036a9fe5a849060159383be2ff6249c51a62 (diff)
Manage dependency installation and removal by tapping into makepkg
-rwxr-xr-xclean-pacman52
1 files changed, 52 insertions, 0 deletions
diff --git a/clean-pacman b/clean-pacman
new file mode 100755
index 0000000..0c22ef0
--- /dev/null
+++ b/clean-pacman
@@ -0,0 +1,52 @@
+#!/bin/bash
+# Copyright 2012 Nicolás Reynolds <fauno@parabola.nu> Licensed under GPLv3
+#
+# Smart cleanup of the chroot, restores chroot to its original state but also
+# leaves the dependencies needed by the current package.
+#
+# Useful when you're building a lot of packages one after another and they
+# share some dependencies.
+#
+# Logic: tap into `makepkg -s`
+#
+# Use it as the PACMAN var for makepkg: `PACMAN=$0 makepkg`
+
+set -e
+set -x
+
+cleanup_log=/tmp/libretools-cleanup.log
+cmd="$1"; shift
+# make -Rn respect PACMAN_OPTS
+flags=($(echo "$@" | grep -o "\-\-no\(confirm\|progressbar\)" || true))
+args="$@"
+
+case $cmd in
+# Collect the packages that are going to be installed, but use a clean database to
+# get the full needed list
+# See update-cleansystem
+ -T)
+# Use sudo because $0 is run as normal user
+ sudo pacman -b "${BD:-/var/lib/libretools/clean}" -Sy
+ sudo pacman -b "${BD:-/var/lib/libretools/clean}" \
+ -Sp \
+ --print-format "%n" \
+ ${args[@]} >>${cleanup_log}
+ ;;
+# Diff against previously installed packages and remove the unneeded ones
+ -S)
+ cleanup=($(comm -23 \
+ <(pacman -Qq | sort) \
+ <(cat /etc/libretools.d/cleansystem ${cleanup_log} | sort -u)
+ ))
+
+ if [ ${#cleanup[@]} -gt 0 ]; then
+# At this point $0 is run as root
+ pacman -Rn ${flags[@]} ${cleanup[@]}
+ fi
+ ;;
+# Remove the cleanup log at the end
+ -R) rm ${cleanup_log} ;;
+esac
+
+# Make makepkg dreams come true
+pacman $cmd ${args[@]}