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