blob: 675afa2defcfb1b0558a0334a1d29730bba88a02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#!/bin/sh
## live-build(7) - System Build Scripts
## Copyright (C) 2016-2020 The Debian Live team
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.
Exit ()
{
local VALUE=$1
if [ "${_DEBUG}" = "true" ]
then
# Dump variables
set | grep -e ^LB
fi
# Skip if we have not yet completed the initial bootstrapping (bootstrap_debootstrap)
# (nothing to be done; avoids unhelpful messages)
if ! Stagefile_exists bootstrap; then
return ${VALUE}
fi
# Always exit true in case we are not able to unmount
# (e.g. due to running processes in chroot from user customizations)
Echo_message "Begin unmounting filesystems..."
local DIRECTORY
if [ -e /proc/mounts ]
then
for DIRECTORY in $(awk -v dir="${PWD}/chroot/" '$2 ~ dir { print $2 }' /proc/mounts | sort -r)
do
umount ${DIRECTORY} > /dev/null 2>&1 || true
done
else
for DIRECTORY in /dev/shm /dev/pts /dev /proc /selinux /sys /root/config
do
umount -f chroot/${DIRECTORY} > /dev/null 2>&1 || true
done
fi
STAGEFILES_DIR="$(Stagefiles_dir)"
rm -f "${STAGEFILES_DIR}"/chroot_devpts
rm -f "${STAGEFILES_DIR}"/chroot_proc
rm -f "${STAGEFILES_DIR}"/chroot_selinuxfs
rm -f "${STAGEFILES_DIR}"/chroot_sysfs
Echo_message "Saving caches..."
# We can't really know at which part we're failing,
# but let's assume that if there's any binary stage file arround
# we are in binary stage.
if ls "${STAGEFILES_DIR}"/binary* > /dev/null 2>&1
then
Save_package_cache binary
else
Save_package_cache chroot
fi
return ${VALUE}
}
Exit_exit ()
{
local VALUE=$?
if [ "${VALUE}" -ne 0 ]; then
Echo_error "An unexpected failure occurred, exiting..."
fi
Exit ${VALUE}
}
Exit_other ()
{
local VALUE=$?
Echo_warning "Unexpected early exit caught, attempting cleanup..."
Exit ${VALUE}
}
Setup_clean_exit ()
{
Echo_message "Setting up clean exit handler"
trap 'Exit_other' HUP INT QUIT TERM
trap 'Exit_exit' EXIT
}
|