summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolás Reynolds <fauno@kiwwwi.com.ar>2012-09-22 18:47:21 -0300
committerNicolás Reynolds <fauno@kiwwwi.com.ar>2012-09-22 18:47:21 -0300
commita323ff09d756dd06a559586467c84dbe78069060 (patch)
tree72ef17c8ece9b29e83634340cd78a5e3cba4ac10
parentcddf27b728fd46157685b3791245fed53393cb18 (diff)
Deprecate clean-pacman in favor of smart chcleanup
Chcleanup compares the currently installed packages with a clean system list of packages + the package dependencies and removes the leftovers. Treepkg runs it as pre-build hook, so FULLBUILDCMD finds only the needed dependencies.
-rwxr-xr-xchcleanup44
-rwxr-xr-xclean-pacman74
-rw-r--r--libretools.conf17
-rwxr-xr-xtreepkg5
4 files changed, 58 insertions, 82 deletions
diff --git a/chcleanup b/chcleanup
index 7074b84..e689a4b 100755
--- a/chcleanup
+++ b/chcleanup
@@ -1,11 +1,49 @@
#!/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
[ ! -f /etc/libretools.d/cleansystem ] && exit 1
+[ ! -d "${DB:-/var/lib/libretools/clean}"/sync ] && exit 1
+
+source $(dirname $0)/libremessages
+
+msg "Cleaning chroot..."
+
+cleanup_log=/tmp/libretools-cleanup.log
+touch ${cleanup_log}
+
+# If we're running makepkg
+if [ -f PKGBUILD ]; then
+ source PKGBUILD || true
+
+# 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" \
+ ${depends[@]} ${makedepends[@]} ${checkdepends[@]} \
+ >${cleanup_log}
+fi
+
+# Diff installed packages against a clean chroot and needed packages,
+# then remove leftovers
+packages=($(comm -23 <(pacman -Qq | sort) \
+ <(cat /etc/libretools.d/cleansystem ${cleanup_log} | sort -u)
+ ))
-packages=($(comm -23 <(pacman -Qq | sort) <(sort /etc/libretools.d/cleansystem)))
+[ ${#packages[@]} -eq 0 ] && exit 0
-echo "Removing: ${packages[@]}"
+msg2 "Removing ${#packages[@]} packages: ${packages[@]}"
-sudo pacman --noconfirm -Rcs ${packages[@]}
+# Only remove leftovers, -Rcs removes too much
+sudo pacman --noconfirm -Rn ${packages[@]}
exit $?
diff --git a/clean-pacman b/clean-pacman
deleted file mode 100755
index 2bfa225..0000000
--- a/clean-pacman
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/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 already installed that are needed by the current
-# package. In other words, it removes everything that's left.
-#
-# Useful when you're building a lot of packages one after another and they
-# share some dependencies.
-#
-# Logic: tap into `makepkg -sr`, collect required packages and remove the
-# 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
-
-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
-
-# Collect the packages that are going to be installed, but use a clean database
-# to get the full needed list.
-# See update-cleansystem
- -T)
- 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
-# 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
- cleanup=($(comm -23 \
- <(pacman -Qq | sort) \
- <(cat /etc/libretools.d/cleansystem ${cleanup_log} | sort -u)
- ))
-
- if [ ${#cleanup[@]} -gt 0 ]; then
- 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}" "${checkdep}"
- fi
- ;;
-# DON'T LET MAKEPKG DO REMOVALS OF ITS OWN
- -R) exit 0;;
-esac
-
-# Make makepkg dreams come true
-pacman $@
diff --git a/libretools.conf b/libretools.conf
index 514c37d..40f92dc 100644
--- a/libretools.conf
+++ b/libretools.conf
@@ -30,9 +30,6 @@ CACHEDIR=`grep "^#\?CacheDir" /etc/pacman.conf | cut -d'=' -f2`
## Parabola hostname (should be the same used on ssh_config
PARABOLAHOST=parabola
-## Run a command before releasing a package (ie. SSH connection, SSH tunnel, etc.)
-HOOKPRERELEASE="ssh -fN parabola"
-
## Server destination of libre packages
# Don't change unless you know what you're doing and you won't screw
# anything ;)
@@ -52,6 +49,20 @@ ABSLIBREGIT=http://projects.parabolagnulinux.org/abslibre.git
FULLBUILDCMD="sudo libremakepkg -cuN"
# Cross compiling fullkpg
# FULLBUILDCMD="sudo libremakepkg -cuN -d '/path/to/cross-compiling/chroot'"
+# Build from within the chroot (or host system)
+# FULLBUILDCMD="makepkg -sL --noconfirm"
+
+# Run a command before releasing a package (ie. SSH connection, SSH tunnel, etc.)
+HOOKPRERELEASE="ssh -fN parabola"
+
+# Run a command before running FULLBUILDCMD, usually to cleanup uneeded packages
+# Note! chcleanup *is not* chroot aware, if you run it as it is it will cleanup
+# your system
+# HOOKPREBUILD="chcleanup"
+
+# Locally release the package or any other action after running FULLBUILDCMD
+# succesfully
+# HOOKLOCALRELEASE=""
## Toru
# Section for toru's vars
diff --git a/treepkg b/treepkg
index 8ba2add..a22df71 100755
--- a/treepkg
+++ b/treepkg
@@ -203,8 +203,9 @@ if [ ${DEPTH} -eq 0 ]; then
pushd "${BUILDDIR}/${_pkg}" >/dev/null
sudo pacman -Syu --noconfirm
-# Pass the PACMAN env var to makepkg
- PACMAN=$(dirname $0)/clean-pacman ${FULLBUILDCMD}
+ ${HOOKPREBUILD}
+
+ ${FULLBUILDCMD}
# Run local release hook with $1 = $repo
${HOOKLOCALRELEASE} $(egrep ";${_pkg#*_};" "${BUILDORDER}" | cut -d';' -f6)