From 8044d776d8e2fc310e1bd0953485dd336b198326 Mon Sep 17 00:00:00 2001 From: m8in Date: Mon, 22 Jun 2026 01:55:40 +0200 Subject: [PATCH] Better Layout of messages --- core/base.module.sh | 18 ++++++++++------- module/print.module.sh | 20 +++++++++---------- script/host/zfs/composition-sync/sync-send.sh | 3 ++- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/core/base.module.sh b/core/base.module.sh index 8289160..cf7f448 100755 --- a/core/base.module.sh +++ b/core/base.module.sh @@ -216,17 +216,21 @@ function base.abort() { && exit 1 [ "${1:+isset}" != "isset" ] \ - && base.printWithColor LIGHTRED "\nScript ${CIS[SCRIPTNAME]} aborted!\n\n" >&2 \ + && base.printWithColor LIGHTRED "\nABORT (" >&2 \ + && base.printWithColor WHITE " ${CIS[SCRIPTNAME]}" >&2 \ + && base.printWithColor LIGHTRED ")!\n\n" >&2 \ && exit 1 [ "${2:+isset}" != "isset" ] \ - && base.printWithColor LIGHTRED "\nScript ${CIS[SCRIPTNAME]} aborted!\n" >&2 \ - && base.printWithColor WHITE "${1:?"Missing parameter MESSAGE."}\n\n" >&2 \ + && base.printWithColor LIGHTRED "\nABORT (" >&2 \ + && base.printWithColor WHITE "${CIS[SCRIPTNAME]}" >&2 \ + && base.printWithColor LIGHTRED "): ${1:?"Missing parameter MESSAGE."}\n\n" >&2 \ && exit 1 - base.printWithColor LIGHTRED "\nScript ${CIS[SCRIPTNAME]} aborted!\n" >&2 - base.printWithColor WHITE "${1:?"Missing parameter MESSAGE."}\n" >&2 - base.printWithColor CYAN "TIP: ${2:?"Missing parameter TIP."}:\n" >&2 + base.printWithColor LIGHTRED "\nABORT (" >&2 + base.printWithColor WHITE "${CIS[SCRIPTNAME]}" >&2 + base.printWithColor LIGHTRED "): ${1:?"Missing parameter MESSAGE."}\n" >&2 + base.printWithColor YELLOW "Reason: ${2:?"Missing parameter REASON."}\n" >&2 while [ -n "${3}" ]; do base.printWithColor LIGHTGREY " ${3:-""}\n" >&2 shift @@ -460,7 +464,7 @@ elif [ "${CIS[SET]}" == "ready" ]; then base.abort "Module '${BASH_SOURCE[0]}' already loaded." else # If not exists, define a global array 'COLOR' - trap "base.abort ' User-initiated termination.'" INT \ + trap "base.abort 'User-initiated termination.'" INT \ && declare -A -g COLOR=([SET]=unprepared) \ && prepare.setCOLOR \ && prepare.setPATH "/bin/grep" \ diff --git a/module/print.module.sh b/module/print.module.sh index ad88b39..167b0e6 100755 --- a/module/print.module.sh +++ b/module/print.module.sh @@ -67,25 +67,25 @@ function print.fail() { #Function, for failures. function print.failure() { [ "${1:+isset}" != "isset" ] \ - && base.printWithColor LIGHTRED "\nFAILURE:" >&2 \ - && base.printWithColor WHITE " ${CIS[SCRIPTNAME]}\n\n" >&2 \ + && base.printWithColor LIGHTRED "FAILURE (" >&2 \ + && base.printWithColor WHITE " ${CIS[SCRIPTNAME]}" >&2 \ + && base.printWithColor LIGHTRED ")!\n" >&2 \ && return 0 [ "${2:+isset}" != "isset" ] \ - && base.printWithColor LIGHTRED "\nFAILURE:" >&2 \ - && base.printWithColor WHITE " ${CIS[SCRIPTNAME]}\n" >&2 \ - && base.printWithColor WHITE " ${1:?"Missing parameter MESSAGE."}\n\n" >&2 \ + && base.printWithColor LIGHTRED "FAILURE (" >&2 \ + && base.printWithColor WHITE "${CIS[SCRIPTNAME]}" >&2 \ + && base.printWithColor LIGHTRED "): ${1:?"Missing parameter MESSAGE."}\n" >&2 \ && return 0 - base.printWithColor LIGHTRED "\nFAILURE:" >&2 - base.printWithColor WHITE " ${CIS[SCRIPTNAME]}\n" >&2 - base.printWithColor WHITE " ${1:?"Missing parameter MESSAGE."}\n" >&2 - base.printWithColor CYAN "TIP: ${2:?"Missing parameter TIP."}:\n" >&2 + base.printWithColor LIGHTRED "FAILURE (" >&2 + base.printWithColor WHITE "${CIS[SCRIPTNAME]}" >&2 + base.printWithColor LIGHTRED "): ${1:?"Missing parameter MESSAGE."}\n" >&2 + base.printWithColor CYAN "TIP: ${2:?"Missing parameter TIP."}\n" >&2 while [ -n "${3}" ]; do base.printWithColor LIGHTGREY " ${3:-""}\n" >&2 shift done - echo >&2 return 0 } diff --git a/script/host/zfs/composition-sync/sync-send.sh b/script/host/zfs/composition-sync/sync-send.sh index be22d0d..81754e3 100755 --- a/script/host/zfs/composition-sync/sync-send.sh +++ b/script/host/zfs/composition-sync/sync-send.sh @@ -139,7 +139,8 @@ base.set RECEIVERS_SNAPSHOT "${4}" "${REGEX[SNAPSHOT]}" optional base.set RESUME_TOKEN "${5}" '^[a-zA-Z0-9][a-zA-Z0-9._:-]*$' optional ! composition.shouldBeSyncedByGivenHost "${COMPOSITION}" "${RECEIVERHOST}" \ - && base.abort "The host '${RECEIVERHOST}' is no sync-host for composition: '${COMPOSITION}'" + && base.abort "no sync-host available" \ + "Host '${RECEIVERHOST}' is no sync-host for composition: '${COMPOSITION}'" # Resume mode if [ "${RECEIVERS_SNAPSHOT}" == "@RESUME" ] && [ -n "${RESUME_TOKEN}" ]; then