From 39c4922e42afb781bb664e22eef2d90f94feb3c9 Mon Sep 17 00:00:00 2001 From: d3v1l0n Date: Tue, 24 Dec 2024 02:54:26 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20build:=20some=20major=20improvem?= =?UTF-8?q?ents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- snigdhaos-libs/snigdhaos.shlib | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/snigdhaos-libs/snigdhaos.shlib b/snigdhaos-libs/snigdhaos.shlib index 1fa20413..8fdc2a9a 100755 --- a/snigdhaos-libs/snigdhaos.shlib +++ b/snigdhaos-libs/snigdhaos.shlib @@ -2,14 +2,29 @@ snigdhaoslib_add_update_notice() { # Ensure the directory exists - mkdir -p /var/lib/snigdhaos/tmp + if ! mkdir -p /var/lib/snigdhaos/tmp; then + echo "Error: Failed to create directory /var/lib/snigdhaos/tmp" >&2 + return 1 + fi # Get the current date current_date=$(date +%F) - - # Replace multiple spaces with a single space in the input string + + # Ensure the input message is not empty + if [ -z "$1" ]; then + echo "Error: No update message provided." >&2 + return 1 + fi + + # Replace multiple spaces with a single space message="${1//[[:space:]]+/ }" # Append the message to the file with the current date - echo "$current_date $message" >> /var/lib/snigdhaos/tmp/update_notices + if ! printf "%s %s\n" "$current_date" "$message" >> /var/lib/snigdhaos/tmp/update_notices; then + echo "Error: Failed to write to /var/lib/snigdhaos/tmp/update_notices" >&2 + return 1 + fi + + # Optionally, display a success message (for debugging/logging purposes) + echo "Update notice successfully added for $current_date." }