From 6cec4a7a74708bc70d7572b85019bb9ae0332e47 Mon Sep 17 00:00:00 2001 From: Lyndon Brown Date: Tue, 10 Mar 2020 19:54:08 +0000 Subject: [PATCH] exit: fix no /usr/bin/env error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 ``` --- functions/exit.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/functions/exit.sh b/functions/exit.sh index 0aa334a5c..9add3612c 100755 --- a/functions/exit.sh +++ b/functions/exit.sh @@ -18,6 +18,12 @@ Exit () 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 [ ! -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) Echo_message "Begin unmounting filesystems..."