summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 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
}