source: live-build/trunk/fuentes/functions/exit.sh @ 900

Last change on this file since 900 was 900, checked in by kbut, 3 years ago

add original source

  • Property svn:executable set to *
File size: 1.4 KB
Line 
1#!/bin/sh
2
3## live-build(7) - System Build Scripts
4## Copyright (C) 2006-2012 Daniel Baumann <daniel@debian.org>
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.
9
10
11Exit ()
12{
13        VALUE="${?}"
14
15        if [ "${_DEBUG}" = "true" ]
16        then
17                # Dump variables
18                set | grep -e ^LB
19        fi
20
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..."
24
25        if [ -e /proc/mounts ]
26        then
27                for DIRECTORY in $(awk -v dir="${PWD}/chroot/" '$2 ~ dir { print $2 }' /proc/mounts | sort -r)
28                do
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
33                do
34                        umount -f chroot/${DIRECTORY} > /dev/null 2>&1 || true
35                done
36        fi
37
38        rm -f .build/chroot_devpts
39        rm -f .build/chroot_proc
40        rm -f .build/chroot_selinuxfs
41        rm -f .build/chroot_sysfs
42
43        Echo_message "Saving caches..."
44
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.
48
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
54        fi
55
56        return ${VALUE}
57}
58
59Setup_cleanup ()
60{
61        Echo_message "Setting up cleanup function"
62        trap 'Exit' EXIT HUP INT QUIT TERM
63}
Note: See TracBrowser for help on using the repository browser.