From a323ff09d756dd06a559586467c84dbe78069060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Reynolds?= Date: Sat, 22 Sep 2012 18:47:21 -0300 Subject: 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. --- chcleanup | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'chcleanup') diff --git a/chcleanup b/chcleanup index 7074b84..e689a4b 100755 --- a/chcleanup +++ b/chcleanup @@ -1,11 +1,49 @@ #!/bin/bash +# (c) Nicolás Reynolds +# 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 $? -- cgit v1.2.3-2-g168b From 08f13bd1f0a0d0e742f2a6e3816d878f2a23da5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Reynolds?= Date: Sat, 22 Sep 2012 20:20:27 -0300 Subject: Remove temp file --- chcleanup | 3 +++ 1 file changed, 3 insertions(+) (limited to 'chcleanup') diff --git a/chcleanup b/chcleanup index e689a4b..1252e66 100755 --- a/chcleanup +++ b/chcleanup @@ -46,4 +46,7 @@ msg2 "Removing ${#packages[@]} packages: ${packages[@]}" # Only remove leftovers, -Rcs removes too much sudo pacman --noconfirm -Rn ${packages[@]} +# Cleanup +rm -f ${cleanup_log} + exit $? -- cgit v1.2.3-2-g168b From 6c95ce9aedf6b1e9353e48f1e52e9989a563980b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Reynolds?= Date: Mon, 1 Oct 2012 11:56:51 -0300 Subject: Correctly set CARCH --- chcleanup | 2 ++ 1 file changed, 2 insertions(+) (limited to 'chcleanup') diff --git a/chcleanup b/chcleanup index 1252e66..9a27d49 100755 --- a/chcleanup +++ b/chcleanup @@ -13,6 +13,8 @@ set -e [ ! -d "${DB:-/var/lib/libretools/clean}"/sync ] && exit 1 source $(dirname $0)/libremessages +source /etc/makepkg.conf +source ${HOME}/.makepkg.conf 2>/dev/null|| true msg "Cleaning chroot..." -- cgit v1.2.3-2-g168b From eda9bd59c2d8919f90aa72cf6cffd545d7bd2295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Reynolds?= Date: Wed, 17 Oct 2012 22:39:27 -0300 Subject: Don't fail if depends are empty --- chcleanup | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'chcleanup') diff --git a/chcleanup b/chcleanup index 9a27d49..5fdbc58 100755 --- a/chcleanup +++ b/chcleanup @@ -25,14 +25,19 @@ touch ${cleanup_log} if [ -f PKGBUILD ]; then source PKGBUILD || true + check=(${depends[@]} ${makedepends[@]} ${checkdepends[@]}) + + if [ ${#check[@]} -ne 0 ]; then + # Update the cleansystem database - sudo pacman -b "${BD:-/var/lib/libretools/clean}" -Sy + 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} + sudo pacman -b "${BD:-/var/lib/libretools/clean}" \ + -Sp \ + --print-format "%n" \ + ${check[@]} \ + >${cleanup_log} + fi fi # Diff installed packages against a clean chroot and needed packages, @@ -43,7 +48,7 @@ packages=($(comm -23 <(pacman -Qq | sort) \ [ ${#packages[@]} -eq 0 ] && exit 0 -msg2 "Removing ${#packages[@]} packages: ${packages[@]}" +msg2 "Removing %d packages: %s" ${#packages[@]} "${packages[@]}" # Only remove leftovers, -Rcs removes too much sudo pacman --noconfirm -Rn ${packages[@]} -- cgit v1.2.3-2-g168b From b4c8f17a6d97b63589b624d726e10d64cbd743ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Reynolds?= Date: Wed, 17 Oct 2012 22:59:52 -0300 Subject: fix printf --- chcleanup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'chcleanup') diff --git a/chcleanup b/chcleanup index 5fdbc58..b5f631c 100755 --- a/chcleanup +++ b/chcleanup @@ -48,7 +48,7 @@ packages=($(comm -23 <(pacman -Qq | sort) \ [ ${#packages[@]} -eq 0 ] && exit 0 -msg2 "Removing %d packages: %s" ${#packages[@]} "${packages[@]}" +msg2 "Removing %d packages" ${#packages[@]} # Only remove leftovers, -Rcs removes too much sudo pacman --noconfirm -Rn ${packages[@]} -- cgit v1.2.3-2-g168b