2007-09-23 08:04:50 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2010-09-02 11:12:37 +00:00
|
|
|
## live-build(7) - System Build Scripts
|
2020-03-11 09:07:21 -01:00
|
|
|
## Copyright (C) 2016-2020 The Debian Live team
|
2015-01-04 18:05:39 -01:00
|
|
|
## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
|
2010-09-02 11:12:37 +00:00
|
|
|
##
|
2012-07-29 23:59:00 +00:00
|
|
|
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
|
2010-09-02 11:12:37 +00:00
|
|
|
## This is free software, and you are welcome to redistribute it
|
|
|
|
## under certain conditions; see COPYING for details.
|
|
|
|
|
2007-09-23 08:04:50 +00:00
|
|
|
|
|
|
|
Exit ()
|
|
|
|
{
|
2020-03-12 17:34:36 -01:00
|
|
|
local VALUE=$1
|
2009-10-19 11:52:54 +00:00
|
|
|
|
2009-12-13 19:17:45 -01:00
|
|
|
if [ "${_DEBUG}" = "true" ]
|
2007-09-23 08:04:50 +00:00
|
|
|
then
|
2007-09-23 08:04:51 +00:00
|
|
|
# Dump variables
|
2010-12-13 21:36:01 -01:00
|
|
|
set | grep -e ^LB
|
2007-09-23 08:04:50 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-10 18:54:08 -01:00
|
|
|
# Skip if we have not yet completed the initial bootstrapping (bootstrap_debootstrap)
|
|
|
|
# (nothing to be done; avoids unhelpful messages)
|
2020-05-02 13:49:45 +00:00
|
|
|
if ! Stagefile_exists bootstrap; then
|
2020-03-10 18:54:08 -01:00
|
|
|
return ${VALUE}
|
|
|
|
fi
|
|
|
|
|
2008-10-14 19:44:48 +00:00
|
|
|
# Always exit true in case we are not able to unmount
|
|
|
|
# (e.g. due to running processes in chroot from user customizations)
|
2008-10-19 15:02:28 +00:00
|
|
|
Echo_message "Begin unmounting filesystems..."
|
2009-12-23 20:27:18 -01:00
|
|
|
|
2020-03-17 16:33:31 -01:00
|
|
|
local DIRECTORY
|
2009-12-23 20:27:18 -01:00
|
|
|
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
|
2021-01-13 23:44:30 -01:00
|
|
|
for DIRECTORY in /dev/shm /dev/pts /dev /proc /sys/fs/selinux /sys /root/config
|
2009-12-23 20:27:18 -01:00
|
|
|
do
|
|
|
|
umount -f chroot/${DIRECTORY} > /dev/null 2>&1 || true
|
|
|
|
done
|
|
|
|
fi
|
2009-10-19 11:52:54 +00:00
|
|
|
|
2020-05-02 13:49:45 +00:00
|
|
|
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
|
2012-01-22 20:31:27 -01:00
|
|
|
|
2011-09-07 18:00:40 +00:00
|
|
|
Echo_message "Saving caches..."
|
2011-07-19 09:13:17 +00:00
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
2020-05-02 13:49:45 +00:00
|
|
|
if ls "${STAGEFILES_DIR}"/binary* > /dev/null 2>&1
|
2011-07-19 09:13:17 +00:00
|
|
|
then
|
2015-01-06 02:46:37 -01:00
|
|
|
Save_package_cache binary
|
2011-07-19 09:13:17 +00:00
|
|
|
else
|
2015-01-06 02:46:37 -01:00
|
|
|
Save_package_cache chroot
|
2011-07-19 09:13:17 +00:00
|
|
|
fi
|
|
|
|
|
2009-10-19 11:52:54 +00:00
|
|
|
return ${VALUE}
|
2007-09-23 08:04:50 +00:00
|
|
|
}
|
2008-10-19 14:58:29 +00:00
|
|
|
|
2020-03-12 17:34:36 -01:00
|
|
|
Exit_exit ()
|
|
|
|
{
|
|
|
|
local VALUE=$?
|
|
|
|
if [ "${VALUE}" -ne 0 ]; then
|
|
|
|
Echo_error "An unexpected failure occurred, exiting..."
|
|
|
|
fi
|
2020-03-13 14:41:22 -01:00
|
|
|
Exit ${VALUE}
|
2020-03-12 17:34:36 -01:00
|
|
|
}
|
|
|
|
|
|
|
|
Exit_other ()
|
|
|
|
{
|
|
|
|
local VALUE=$?
|
|
|
|
Echo_warning "Unexpected early exit caught, attempting cleanup..."
|
2020-03-13 14:41:22 -01:00
|
|
|
Exit ${VALUE}
|
2020-03-12 17:34:36 -01:00
|
|
|
}
|
|
|
|
|
2015-02-05 02:30:47 -01:00
|
|
|
Setup_clean_exit ()
|
2008-10-19 14:58:29 +00:00
|
|
|
{
|
2015-02-05 02:30:47 -01:00
|
|
|
Echo_message "Setting up clean exit handler"
|
2020-03-12 17:34:36 -01:00
|
|
|
trap 'Exit_other' HUP INT QUIT TERM
|
|
|
|
trap 'Exit_exit' EXIT
|
2008-10-19 14:58:29 +00:00
|
|
|
}
|