summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2012-12-02 21:52:21 -0500
committerLuke Shumaker <LukeShu@sbcglobal.net>2012-12-02 21:52:21 -0500
commit69630547758d4aefff8a6cd12336935fa9fdca1c (patch)
tree5d64ecf79c70759ed4e4e8eef68fcf7fc47413ed
parent3f5470e4c19bcc481fb10eee2fe88a081b568fe4 (diff)
librechroot: clean up files when done
-rwxr-xr-xsrc/chroot-tools/librechroot42
1 files changed, 21 insertions, 21 deletions
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot
index fda72d4..38d7362 100755
--- a/src/chroot-tools/librechroot
+++ b/src/chroot-tools/librechroot
@@ -28,6 +28,13 @@
# This gives us the functions:
# - sync
+cleanup=(':');
+cleanup() {
+ for cmd in "${cleanup[@]}"; do
+ $cmd
+ done
+}
+
cmd=${0##*/}
usage() {
echo "Usage: $cmd [OPTIONS] "
@@ -111,40 +118,33 @@ main() {
########################################################################
+ trap cleanup EXIT
case "$mode" in
clean_repo)
- rm -rf "${copydir}/repo"
- mkdir "${copydir}/repo"
+ rm -rf "${copydir}/repo/*"
bsdtar -czf "${copydir}/repo/repo.db.tar.gz" -T /dev/null
ln -s "repo.db.tar.gz" "${copydir}/repo/repo.db"
;;
clean_pacman)
+ cleanup+=("rm -f '$copydir/clean' '$copydir/chrootexec'")
cp -a "$(which chcleanup)" "${copydir}/clean"
- echo '#!/bin/bash' > "${copydir}/cleanstrap"
- echo 'mkdir /build' >> "${copydir}/cleanstrap"
- echo 'cd /build; /clean' >> "${copydir}/cleanstrap"
- chmod 755 "${copydir}/cleanstrap"
- archroot "${archroot_args[@]}" "${copydir}" -r /cleanstrap
+ echo '#!/bin/bash' > "${copydir}/chrootexec"
+ echo 'mkdir /build' >> "${copydir}/chrootexec"
+ echo 'cd /build; /clean' >> "${copydir}/chrootexec"
+ chmod 755 "${copydir}/chrootexec"
+ archroot "${archroot_args[@]}" "${copydir}" -r /chrootexec
;;
install_file)
+ cleanup+=("rm '$copydir/${ARG##*/}'")
cp "$ARG" "$copydir/${ARG##*/}"
- archroot "${archroot_args[@]}" "$copydir" -r "pacman -U /${ARG##*/} --noconfirm"
- rm "$copydir/${ARG##*/}"
- ;;
- install_pkg)
- archroot "${archroot_args[@]}" "$copydir" -i $ARG
+ archroot "${archroot_args[@]}" "${copydir}" -r "pacman -U /${ARG##*/} --noconfirm"
;;
+ install_pkg) archroot "${archroot_args[@]}" "${copydir}" -i $ARG ;;
noop) :;;
- run)
- archroot "${archroot_args[@]}" "${copydir}" -r "$ARG"
- ;;
+ run) archroot "${archroot_args[@]}" "${copydir}" -r "$ARG" ;;
sync) sync;;
- update)
- archroot "${archroot_args[@]}" "${copydir}" -u
- ;;
- enter)
- archroot "${archroot_args[@]}" "${copydir}" -r bash
- ;;
+ update) archroot "${archroot_args[@]}" "${copydir}" -u ;;
+ enter) archroot "${archroot_args[@]}" "${copydir}" -r bash ;;
esac
}