summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-12-07 12:24:18 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-12-09 14:20:48 -0500
commit056aac864aaa989a17703857e8e0e9b67726fc22 (patch)
treee8fbec3d569f2ac114ff2d26d8e0046513293a0d
parent70e1601042250b395659f4c325ae7a73cbe238ab (diff)
Improve chcleanup, make supporting changes to other tools
chcleanup: * load `CHROOTEXTRAPKGS` from `/etc/libretools.d/chroot.conf` * always cleanup temporary files * properly quote the various arrays used * verify that you are in a chroot librechroot: * write `$copydir/etc/libretools.d/chroot.conf` libremakepkg.gpl2: * use `librechroot` instead of `archroot` directly in `chrootexec()`
-rwxr-xr-xsrc/chroot-tools/chcleanup72
-rwxr-xr-xsrc/chroot-tools/librechroot11
-rwxr-xr-xsrc/chroot-tools/libremakepkg.gpl22
3 files changed, 48 insertions, 37 deletions
diff --git a/src/chroot-tools/chcleanup b/src/chroot-tools/chcleanup
index 17c1f02..821c572 100755
--- a/src/chroot-tools/chcleanup
+++ b/src/chroot-tools/chcleanup
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/bash -eE
# (c) Nicolás Reynolds <fauno@parabola.nu>
# Released under GPLv3
#
@@ -7,51 +7,51 @@
#
# See: HOOKPREBUILD
-set -e
DRYRUN=${DRYRUN:-false}
+source "$(which libremessages)"
-source /etc/makepkg.conf
-source /etc/libretools.conf
-source ${HOME}/.makepkg.conf 2>/dev/null|| true
-
-msg "Cleaning chroot..."
-
-TMPDIR="$(mktemp -d /tmp/$(basename $0)-XXXXX)"
-cleanup_log="${TMPDIR}"/libretools-cleanup.log
-
-cp -a /var/lib/pacman/sync "${TMPDIR}/"
-touch ${cleanup_log}
+if [[ ! -f /.arch-chroot ]] && ! ${DRYRUN}; then
+ error "(chcleanup): Must be run inside of a chroot"
+ exit 1
+fi
+source /etc/libretools.d/chroot.conf
# If we're running makepkg
if [ -f PKGBUILD ]; then
- source PKGBUILD || true
+ source PKGBUILD
+ CHROOTEXTRAPKG+=("${depends[@]}"
+ "${makedepends[@]}"
+ "${checkdepends[@]}")
+fi
- check=(${depends[@]} ${makedepends[@]} ${checkdepends[@]})
+msg "Cleaning chroot..."
-fi
+TEMPDIR="$(mktemp --tmpdir -d $(basename $0).XXXXX)"
+cp -a /var/lib/pacman/sync "${TEMPDIR}/"
+cleanup_log="${TEMPDIR}"/libretools-cleanup.log
# Get the full list of packages needed by dependencies, including the base system
-sudo pacman -b "${TMPDIR}" \
- -Sp \
- --print-format "%n" \
- base base-devel sudo \
- ${CHROOTEXTRAPKG[@]} \
- ${check[@]} \
- >${cleanup_log}
+pacman -b "${TEMPDIR}" \
+ -Sp --print-format "%n" \
+ base base-devel sudo "${CHROOTEXTRAPKG[@]}" \
+ >"${cleanup_log}"
# Diff installed packages against a clean chroot then remove leftovers
-packages=($(comm -23 <(pacman -Qq | sort) \
- <(sort -u ${cleanup_log})))
-
-[ ${#packages[@]} -eq 0 ] && exit 0
-
-msg2 "Removing %d packages" ${#packages[@]}
-
-# Only remove leftovers, -Rcs removes too much
-${DRYRUN} || sudo pacman --noconfirm -Rn ${packages[@]}
-${DRYRUN} && echo ${packages[@]}
-
+packages=($(comm -23 <(pacman -Qq | sort -u) \
+ <(sort -u "${cleanup_log}")))
+
+RET=0
+if [[ ${#packages[@]} != 0 ]]; then
+ msg2 "Removing %d packages" ${#packages[@]}
+
+ if ${DRYRUN}; then
+ echo "${packages[@]}"
+ else
+ # Only remove leftovers, -Rcs removes too much
+ pacman --noconfirm -Rn "${packages[@]}" || RET=$?
+ fi
+fi
# Cleanup
-${DRYRUN} || rm -fr ${TMPDIR}
+rm -rf "${TEMPDIR}"
-exit $?
+exit $RET
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot
index 0a7ba65..52a3bdf 100755
--- a/src/chroot-tools/librechroot
+++ b/src/chroot-tools/librechroot
@@ -116,6 +116,17 @@ main() {
sync
fi
+ mkdir -p $copydir/etc/libretools.d
+ {
+ if [[ -n ${CHROOTEXTRAPKG[@]:-} ]]; then
+ printf 'CHROOTEXTRAPKG=('
+ printf "'%s' " "${CHROOTEXTRAPKG[@]}"
+ printf ')\n'
+ else
+ printf 'CHROOTEXTRAPKG=()\n'
+ fi
+ } > $copydir/etc/libretools.d/chroot.conf
+
########################################################################
trap cleanup EXIT
diff --git a/src/chroot-tools/libremakepkg.gpl2 b/src/chroot-tools/libremakepkg.gpl2
index 9c600ed..3f66589 100755
--- a/src/chroot-tools/libremakepkg.gpl2
+++ b/src/chroot-tools/libremakepkg.gpl2
@@ -98,7 +98,7 @@ cd /build
${cmd}
EOF
chmod 755 "$copydir/chrootexec"
- archroot $flags "$copydir" -r /chrootexec
+ librechroot $flags -n "$CHROOT" -l "$CHROOTCOPY" -r /chrootexec
fi
}