Dropping automagics for casper.
[debian-live-build.git] / functions / exit.sh
blob6ff9cdcf7d72e82ae29a6938ea73009e7192318e
1 #!/bin/sh
3 ## live-build(7) - System Build Scripts
4 ## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
5 ##
6 ## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
7 ## This is free software, and you are welcome to redistribute it
8 ## under certain conditions; see COPYING for details.
11 Exit ()
13 VALUE="${?}"
15 if [ "${_DEBUG}" = "true" ]
16 then
17 # Dump variables
18 set | grep -e ^LB
21 # Always exit true in case we are not able to unmount
22 # (e.g. due to running processes in chroot from user customizations)
23 Echo_message "Begin unmounting filesystems..."
25 if [ -e /proc/mounts ]
26 then
27 for DIRECTORY in $(awk -v dir="${PWD}/chroot/" '$2 ~ dir { print $2 }' /proc/mounts | sort -r)
29 umount ${DIRECTORY} > /dev/null 2>&1 || true
30 done
31 else
32 for DIRECTORY in /dev/shm /dev/pts /dev /proc /selinux /sys /root/config
34 umount -f chroot/${DIRECTORY} > /dev/null 2>&1 || true
35 done
38 rm -f .build/chroot_devpts
39 rm -f .build/chroot_proc
40 rm -f .build/chroot_selinuxfs
41 rm -f .build/chroot_sysfs
43 Echo_message "Saving caches..."
45 # We can't really know at which part we're failing,
46 # but let's assume that if there's any binary stage file arround
47 # we are in binary stage.
49 if ls .build/binary* > /dev/null 2>&1
50 then
51 Save_cache cache/packages.binary
52 else
53 Save_cache cache/packages.chroot
56 return ${VALUE}
59 Setup_cleanup ()
61 Echo_message "Setting up cleanup function"
62 trap 'Exit' EXIT HUP INT QUIT TERM