mklive.sh: fix issues with error handling and unmounting pseudofs

- add some error handling to `umount_pseudofs`
- disable the trap before running `error_out` to stop it running multiple times
- add `--one-file-system` to ensure that the `rm -rf` can't screw you

fixes #364
This commit is contained in:
classabbyamp 2024-01-16 11:59:13 -05:00
parent 498083d936
commit 44a30c43f6
No known key found for this signature in database
GPG Key ID: 6BE0755918A4C7F5
1 changed files with 13 additions and 8 deletions

View File

@ -24,7 +24,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#-
trap 'error_out $? $LINENO' INT TERM 0
umask 022
. ./lib.sh
@ -52,14 +51,18 @@ mount_pseudofs() {
done
}
umount_pseudofs() {
umount -R -f "$ROOTFS"/sys >/dev/null 2>&1
umount -R -f "$ROOTFS"/dev >/dev/null 2>&1
umount -R -f "$ROOTFS"/proc >/dev/null 2>&1
for f in sys dev proc; do
if ! umount -R -f "$ROOTFS/$f"; then
info_msg "ERROR: failed to unmount $ROOTFS/$f/"
return 1
fi
done
}
error_out() {
umount_pseudofs
[ -d "$BUILDDIR" -a -z "$KEEP_BUILDDIR" ] && rm -rf "$BUILDDIR"
exit "${1:=0}"
trap - INT TERM 0
umount_pseudofs || exit "${1:-0}"
[ -d "$BUILDDIR" ] && [ -z "$KEEP_BUILDDIR" ] && rm -rf --one-file-system "$BUILDDIR"
exit "${1:-0}"
}
usage() {
@ -271,7 +274,7 @@ generate_grub_efi_boot() {
}
generate_squashfs() {
umount_pseudofs
umount_pseudofs || exit 1
# Find out required size for the rootfs and create an ext3fs image off it.
ROOTFS_SIZE=$(du --apparent-size -sm "$ROOTFS"|awk '{print $1}')
@ -366,6 +369,8 @@ if [ "$(id -u)" -ne 0 ]; then
die "Must be run as root, exiting..."
fi
trap 'error_out $? $LINENO' INT TERM 0
if [ -n "$ROOTDIR" ]; then
BUILDDIR=$(mktemp --tmpdir="$ROOTDIR" -d)
else