From 79724e85dcaf6dfafe2437c7f553f0491abb2037 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Thu, 18 Jul 2024 11:13:00 -0400 Subject: [PATCH] swupdate-ab: improve log functions --- .../swupdate/swupdate-ab/update.footer.sh | 22 ++++++++----------- .../swupdate/swupdate-ab/update.header.sh | 22 +++++++++++++------ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/recipes-support/swupdate/swupdate-ab/update.footer.sh b/recipes-support/swupdate/swupdate-ab/update.footer.sh index 6c8e394..53db14e 100644 --- a/recipes-support/swupdate/swupdate-ab/update.footer.sh +++ b/recipes-support/swupdate/swupdate-ab/update.footer.sh @@ -21,15 +21,13 @@ get_destination_partition_device() disk="/dev/$(lsblk -ndo pkname $(findmnt -n -o SOURCE /))" if [ ! -b "${disk}" ]; then - swulog "Error: disk \"${disk}\" not found" - return 1 + log_err "Error: disk \"${disk}\" not found" fi update_dev="${disk}${next_part}" if [ ! -b "${update_dev}" ]; then - swulog "Error: destination partition \"${update_dev}\" not found" - return 1 + log_err "Error: destination partition \"${update_dev}\" not found" fi echo "${update_dev}" @@ -43,8 +41,7 @@ mount_destination_partition() # Create temporary mount point: mnt_point=$(mktemp -q -d /tmp/swupdate-mount.XXXXXX) if [ ${?} -ne 0 ]; then - swulog "Error: cannot create temporary file" - exit 1 + log_err "Error: cannot create temporary file" fi # Mount update partition: @@ -65,7 +62,7 @@ unmount_destination_partition() do_preinst() { update_dev=$(get_destination_partition_device) - swulog "Reformat destination partition: ${update_dev}" + log_info "Reformat destination partition: ${update_dev}" label="$(blkid -s LABEL -o value ${update_dev})" @@ -80,12 +77,12 @@ do_postinst() mount_destination_partition # Perform migration of selected files/folders... - swulog "migrating existing data..." + log_info "migrating existing data..." # Migrate files: for f in ${SWU_PRESERVE_FILES}; do if [ ! -f ${f} ]; then - swulog "warning: missing source file: ${f} (skipping)" + log_warn "warning: missing source file: ${f} (skipping)" continue fi @@ -95,7 +92,7 @@ do_postinst() # The destination folder need to be created in your new SWU archive # with the proper ownership and permissions (can be empty) if [ ! -d ${dst_folder} ]; then - swulog "warning: missing destination folder for file: ${f} (skipping)" + log_warn "warning: missing destination folder for file: ${f} (skipping)" continue fi @@ -106,7 +103,7 @@ do_postinst() # Migrate folders: for d in ${SWU_PRESERVE_FOLDERS}; do if [ ! -d ${d} ]; then - swulog "warning: missing source folder: ${d} (skipping)" + log_warn "warning: missing source folder: ${d} (skipping)" continue fi @@ -134,7 +131,6 @@ case "$1" in do_postinst ;; *) - swulog "unsupported install mode: \"${1}\"" - exit 1 + log_err "unsupported install mode: \"${1}\"" ;; esac diff --git a/recipes-support/swupdate/swupdate-ab/update.header.sh b/recipes-support/swupdate/swupdate-ab/update.header.sh index 50af79c..53df653 100644 --- a/recipes-support/swupdate/swupdate-ab/update.header.sh +++ b/recipes-support/swupdate/swupdate-ab/update.header.sh @@ -8,6 +8,20 @@ set -e trap 'catch $?' EXIT +# Arg1: log message/string +log_info() { + printf "$(basename ${0}): ${*}\n" +} + +log_warn() { + printf >&2 "$(basename ${0}): ${*}\n" +} + +log_err() { + printf >&2 "$(basename ${0}): ${*}\n" + exit 1 +} + catch() { if [ "$1" != "0" ]; then @@ -20,15 +34,9 @@ catch() fi } -# Arg1: log message/string -swulog() -{ - echo "$(basename ${0}): ${1}" -} - FSTYPE="ext4" -swulog "arguments = \"${*}\"" +log_info "arguments = \"${*}\"" if [ $# -lt 2 ]; then exit 1; -- 2.20.1