From d0c8f84c1c02eb885e9c467650772a0625954da5 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 6 Aug 2018 13:17:16 -0400 Subject: chcleanup: More informative output, use pacman -T to speed things up --- src/chroot-tools/chcleanup.in | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src') 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 -- cgit v1.2.2