From 565e8505097e490239a91c106695896f3f058f9b Mon Sep 17 00:00:00 2001 From: "Roberto A. Foglietta" Date: Thu, 15 Dec 2022 17:51:17 +0100 Subject: [PATCH 6/7] In expand last partition trap exitnlog EXIT logs with simpler code improvement, the script log at exit with the status of completion and its full path in this way the - in case of failure - the user will find in dmesg the error and also the script full path to debug. It uses /dev/kmsg to log. Code simplified. Signed-off-by: Roberto A. Foglietta --- .../files/expand-last-partition.sh | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh index 90e8d93..1c8abf0 100755 --- a/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh +++ b/meta/recipes-support/expand-on-first-boot/files/expand-last-partition.sh @@ -7,9 +7,22 @@ # # SPDX-License-Identifier: MIT -set -e +exitnlog() { + ec=$? + set +e + if [ "$ec" != "0" ]; then + echo "ERROR: $0 failed" + else + echo "$0 succeded" + fi >/dev/kmsg + if [ "$ec" != "0" -a -e /etc/unsupervised ]; then + reboot + fi +} +export -f exitnlog +trap exitnlog EXIT -test -e /etc/unsupervised && trap reboot EXIT +set -e udevadm settle @@ -36,7 +49,6 @@ useless_for_now() { MINIMAL_SIZE=$((ALL_PARTS_SIZE + BUFFER_SIZE)) if [ "$DISK_SIZE" -lt "$MINIMAL_SIZE" ]; then echo "Disk is practically already full, doing nothing." >&2 - trap - EXIT exit 0 fi } @@ -80,5 +92,3 @@ case $(lsblk -fno FSTYPE "${LAST_PART}") in umount $tmpdir && rmdir $tmpdir ;; esac - -trap - EXIT -- 2.34.1