summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/chroot-tools/chcleanup46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/chroot-tools/chcleanup b/src/chroot-tools/chcleanup
index fa6a572..0461de2 100755
--- a/src/chroot-tools/chcleanup
+++ b/src/chroot-tools/chcleanup
@@ -18,6 +18,11 @@ else
_() { echo "$@"; }
fi
+plain() {
+ local mesg="$(_ "$1")"; shift
+ printf "${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
msg() {
local mesg="$(_ "$1")"; shift
printf "${GREEN}==>${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
@@ -28,6 +33,11 @@ msg2() {
printf "${BLUE} ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}
+warning() {
+ local mesg="$(_ "$1")"; shift
+ printf "${YELLOW}==> $(gettext "WARNING:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
+}
+
error() {
local mesg="$(_ "$1")"; shift
printf "${RED}==> $(gettext "ERROR:")${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
@@ -51,35 +61,41 @@ if [ -f PKGBUILD ]; then
fi
msg "Cleaning chroot..."
+msg2 "Fetching updated package lists..."
+pacman -Sy || {
+ warning "There was an error updating package lists, ignoring."
+}
-pacman -Sy || true
-
+# Setup the temporary directory
TEMPDIR="$(mktemp --tmpdir -d $(basename $0).XXXXX)"
+trap "rm -rf '$TEMPDIR'" EXIT
+
cp -a /var/lib/pacman/sync "${TEMPDIR}/"
-cleanup_log="${TEMPDIR}"/libretools-cleanup.log
+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 -b "${TEMPDIR}" \
- -Sp --print-format "%n" \
- base-devel "${CHROOTEXTRAPKG[@]}" \
- >"${cleanup_log}"
+ -Sp --print-format "%n" base-devel "${CHROOTEXTRAPKG[@]}" >"$pkglist" || {
+ ret=$?
+ error "Could not create a full list of packages, exiting."
+ plain "This is likely caused by a dependency that could not be found."
+ exit $ret
+}
# Diff installed packages against a clean chroot then remove leftovers
packages=($(comm -23 <(pacman -Qq | sort -u) \
- <(sort -u "${cleanup_log}")))
+ <(sort -u "${pkglist}")))
-RET=0
-if [[ ${#packages[@]} != 0 ]]; then
+if [[ ${#packages[@]} = 0 ]]; then
+ msg2 "No packages to remove"
+else
msg2 "Removing %d packages" ${#packages[@]}
if ${DRYRUN}; then
- echo "${packages[@]}"
+ echo "${packages[*]}"
else
# Only remove leftovers, -Rcs removes too much
- pacman --noconfirm -Rn "${packages[@]}" || RET=$?
+ pacman --noconfirm -Rn "${packages[@]}"
fi
fi
-# Cleanup
-rm -rf "${TEMPDIR}"
-
-exit $RET