summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2018-08-06 13:17:16 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2018-08-06 13:17:16 -0400
commitd0c8f84c1c02eb885e9c467650772a0625954da5 (patch)
treed9c50d2399b5ca085c8a46f0353fcb2ece3927ec /src
parenta7a6fcece742e1b29db1cb5da858c85d7b1dfa76 (diff)
chcleanup: More informative output, use pacman -T to speed things up
Diffstat (limited to 'src')
-rw-r--r--src/chroot-tools/chcleanup.in34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/chroot-tools/chcleanup.in b/src/chroot-tools/chcleanup.in
index d114080..0326716 100644
--- a/src/chroot-tools/chcleanup.in
+++ b/src/chroot-tools/chcleanup.in
@@ -50,6 +50,8 @@ if [[ ! -f /.arch-chroot ]] && ! ${DRYRUN}; then
exit 1
fi
+# Figure out which packages we want
+CHROOTPKG=(base-devel)
# Note: the in-chroot pkgconfdir is non-configurable, this is
# intentionally hard-coded.
source /etc/libretools.d/chroot.conf
@@ -78,13 +80,31 @@ pkglist="${TEMPDIR}"/pkglist.txt
# Get the full list of packages needed by dependencies, including the base system
msg2 "Creating a full list of packages..."
-pacman --dbpath="$TEMPDIR" --hookdir=/var/empty -Sq --needed --dbonly --noconfirm -- base-devel >/dev/null
-if (( ${#CHROOTEXTRAPKG[@]} > 0 )); then
- pacman --dbpath="$TEMPDIR" --hookdir=/var/empty -Sq --needed --dbonly --noconfirm -- "${CHROOTEXTRAPKG[@]}" >/dev/null
-fi
-if (( ${#DEPENDS[@]} > 0 )); then
- pacman --dbpath="$TEMPDIR" --hookdir=/var/empty -Sq --needed --dbonly --noconfirm -- "${DEPENDS[@]}" >/dev/null
-fi
+mkdir "$TEMPDIR/hooks"
+{ echo /usr/share/libalpm/hooks; pacman-conf HookDir; } | while read -r dir; do
+ for hook in "$dir"/*.hook; do
+ ln -sfT -- /dev/null "$TEMPDIR/hooks/${hook##*/}"
+ done
+done
+for var in CHROOTPKG CHROOTEXTRAPKG DEPENDS; do
+ declare -n fullpkgs="$var"
+ mapfile -t missingpkgs < <(pacman --dbpath="$TEMPDIR" -T -- "${fullpkgs[@]}")
+ if (( ${#missingpkgs[@]} == 0 )); then
+ continue
+ fi
+ # Even though `pacman -T` filtered installed packages out,
+ # if still if use --needed because of groups.
+ pacman \
+ --dbpath="$TEMPDIR" --hookdir="$TEMPDIR/hooks" \
+ -S --dbonly --noscriptlet --needed --noconfirm -- "${missingpkgs[@]}" \
+ <&- &>"$TEMPDIR/pacman.txt" || ret=$?
+ if (( ret != 0 )); then
+ error "Could not create a full list of packages, exiting."
+ plain "This is likely caused by a dependency that could not be found."
+ sed 's/^/ > /' <"$TEMPDIR/pacman.txt" >&2
+ exit $ret
+ fi
+done
pacman --dbpath="$TEMPDIR" -Qq >"$pkglist"
# Diff installed packages against a clean chroot then remove leftovers