diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-12-02 21:52:21 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2012-12-09 14:20:48 -0500 |
commit | 9c404ac8da32df78934bb0ce46cdf96af93801e5 (patch) | |
tree | 6ca05098ad71255b48cc14bcb985d342172d6a2b /src/chroot-tools/librechroot | |
parent | 040f4f53f9bdc70fbaf73db1b637fd0b40359b3c (diff) |
librechroot: clean up files when done
Diffstat (limited to 'src/chroot-tools/librechroot')
-rwxr-xr-x | src/chroot-tools/librechroot | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/chroot-tools/librechroot b/src/chroot-tools/librechroot index 990f91c..0a7ba65 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 } |