summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@kiwwwi.com.ar>2012-09-22 18:38:29 -0300
committerNicolás Reynolds <fauno@kiwwwi.com.ar>2012-09-22 18:38:29 -0300
commitcddf27b728fd46157685b3791245fed53393cb18 (patch)
treedb305440cabade6d58a81e9c50d0f2fcedabf699
parent379cb6eb270b0b26ddddb9170c6dcd0f756d1de5 (diff)
Last commit before deprecation
Reason: Too complex, makepkg runs three times and removes packages previously installed
-rwxr-xr-xclean-pacman39
1 files changed, 25 insertions, 14 deletions
diff --git a/clean-pacman b/clean-pacman
index 9ef4a46..2bfa225 100755
--- a/clean-pacman
+++ b/clean-pacman
@@ -12,15 +12,24 @@
# leftovers
#
# Use it as the PACMAN var for makepkg: `PACMAN=$0 makepkg`
+#
+# Notes
+# makepkg runs the following flags three times (depends, makedepends, checkdepends)
+# -T check deps (collect here)
+# -S install missing deps (remove leftovers here)
+# -T check if installed correctly (ignore)
+# -R remove installed deps (skip)
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="$@"
+makepid=$(ps --no-header -o pid -C makepkg | head -n1 | tr -d " ")
+cleanup_log=/tmp/libretools-cleanup-${makepid}.log
+checkdep=/tmp/libretools-dep-check-${makepid}
+
+cmd="$(echo "$@" | grep -o "\-\(T\|S\|R\|Q\)[^ ]*")"
+# remove all flags
+args="$(echo " $@" | sed "s/ \-[^ ]\+//g")"
case $cmd in
@@ -28,36 +37,38 @@ case $cmd in
# to get the full needed list.
# See update-cleansystem
-T)
-# Use sudo because $0 is run as normal user
+ if [ ! -f "${checkdep}" ]; then
+# Use sudo because $0 is run as normal user on -T
# TODO -Sy only once
sudo pacman -b "${BD:-/var/lib/libretools/clean}" -Sy >/dev/null 2>&1
sudo pacman -b "${BD:-/var/lib/libretools/clean}" \
-Sp \
--print-format "%n" \
- ${args[@]} >>${cleanup_log} 2>/dev/null
- ;;
+ ${args[@]} >${cleanup_log} 2>/dev/null
+# Deps are collected, so skip next time
+ touch "${checkdep}"
# Diff against previously installed packages and remove the unneeded ones
#
# We don't collect during -S because we never get here if depencies are met
# during -T
- -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[@]}
+ sudo pacman -Rn --noconfirm ${cleanup[@]} 1>&2
fi
-
+# This is the second -T run
+ else
# Remove the cleanup log at the end
- rm ${cleanup_log}
+ rm "${cleanup_log}" "${checkdep}"
+ fi
;;
# DON'T LET MAKEPKG DO REMOVALS OF ITS OWN
-R) exit 0;;
esac
# Make makepkg dreams come true
-pacman $cmd ${args[@]}
+pacman $@