live-build/functions/exit.sh

71 lines
1.7 KiB
Bash
Raw Normal View History

2007-09-23 08:04:50 +00:00
#!/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.
2007-09-23 08:04:50 +00:00
Exit ()
{
VALUE=$?
if [ "${_DEBUG}" = "true" ]
2007-09-23 08:04:50 +00:00
then
2007-09-23 08:04:51 +00:00
# Dump variables
set | grep -e ^LB
2007-09-23 08:04:50 +00:00
fi
exit: fix no /usr/bin/env error if you execute the bootstrap stage with no internet connection, you get the following output: ``` [2020-03-10 19:18:46] lb bootstrap P: Setting up clean exit handler [2020-03-10 19:18:46] lb bootstrap_cache restore [2020-03-10 19:18:46] lb bootstrap_debootstrap P: Begin bootstrapping system... P: If the following stage fails, the most likely cause of the problem is with your mirror configuration or a caching proxy. P: Running debootstrap (download-only)... I: Retrieving InRelease I: Retrieving Release E: Failed getting release file http://deb.debian.org/debian/dists/buster/Release P: Begin unmounting filesystems... P: Saving caches... chroot: failed to run command ‘/usr/bin/env’: No such file or directory ``` the last line looked suspicious. investigating it turns out that there was a deficiency in the exit handler. when debootstrap fails to download what it needs due to lack of a connection, that failure due to `set -e` causes the Exit() handler to kick in. Part of this includes outputting the "Saving caches..." line, before then making a call to Save_package_cache(). That in turn runs the following command: ``` Chroot chroot "apt-get autoclean" || true ``` The Chroot() function includes a line starting with: ``` ${_LINUX32} chroot "${CHROOT}" /usr/bin/env ``` which is the source of the last output line. the reason we see this unexpected output is that with bootstrapping having failed, there is no /usr/bin/env within the chroot so it is bound to fail. the fact is, the exit handler has no business trying to pretty much anything that it does if the bootstrap_debootstrap stage has not completed. this implements such a restriction and thus resolves the problem of this unexpected and confusing output in the described situation. we will now see: ``` [2020-03-10 19:18:46] lb bootstrap P: Setting up clean exit handler [2020-03-10 19:18:46] lb bootstrap_cache restore [2020-03-10 19:18:46] lb bootstrap_debootstrap P: Begin bootstrapping system... P: If the following stage fails, the most likely cause of the problem is with your mirror configuration or a caching proxy. P: Running debootstrap (download-only)... I: Retrieving InRelease I: Retrieving Release E: Failed getting release file http://deb.debian.org/debian/dists/buster/Release ```
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)
if [ ! -e .build/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)
2008-10-19 15:02:28 +00:00
Echo_message "Begin unmounting filesystems..."
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
rm -f .build/chroot_devpts
rm -f .build/chroot_proc
rm -f .build/chroot_selinuxfs
rm -f .build/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 .build/binary* > /dev/null 2>&1
then
Save_package_cache binary
else
Save_package_cache chroot
fi
return ${VALUE}
2007-09-23 08:04:50 +00:00
}
Setup_clean_exit ()
{
Echo_message "Setting up clean exit handler"
trap 'Exit' EXIT HUP INT QUIT TERM
}