From 381f0806b2c3fc15fb176eb57443d0b6df48aa4b Mon Sep 17 00:00:00 2001 From: eshanized Date: Thu, 9 Jan 2025 15:32:22 +0530 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20perf:=20improve=20with=20l?= =?UTF-8?q?ogging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usr/local/bin/snigdhaos-lsb-release | 30 +++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/usr/local/bin/snigdhaos-lsb-release b/usr/local/bin/snigdhaos-lsb-release index 3b83720..967f475 100755 --- a/usr/local/bin/snigdhaos-lsb-release +++ b/usr/local/bin/snigdhaos-lsb-release @@ -4,23 +4,41 @@ SOURCE_FILE="/usr/local/share/snigdhaos/release/lsb-release-snigdhaos" TARGET_FILE="/etc/lsb-release" +# Function to display a message with a timestamp +log_message() { + echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" +} + echo -echo "Applying lsb Release..." +log_message "Starting the lsb-release update process..." # Check if the source file exists if [[ ! -f "$SOURCE_FILE" ]]; then - echo "Error: Source file '$SOURCE_FILE' does not exist." + log_message "Error: Source file '$SOURCE_FILE' does not exist." + exit 1 +fi + +# Check if the target file is writable (or replaceable) +if [[ -e "$TARGET_FILE" && ! -w "$TARGET_FILE" ]]; then + log_message "Error: Target file '$TARGET_FILE' exists but is not writable. Please check permissions." exit 1 fi # Attempt to copy the source file to the target location if sudo cp "$SOURCE_FILE" "$TARGET_FILE"; then - echo "Successfully copied $SOURCE_FILE to $TARGET_FILE." + log_message "Successfully copied $SOURCE_FILE to $TARGET_FILE." else - echo "Error: Failed to copy $SOURCE_FILE to $TARGET_FILE." + log_message "Error: Failed to copy $SOURCE_FILE to $TARGET_FILE." exit 1 fi -echo -echo "Task Completed!" +# Verify if the file was successfully copied +if [[ -f "$TARGET_FILE" ]]; then + log_message "Verification successful: '$TARGET_FILE' exists." +else + log_message "Error: Verification failed. '$TARGET_FILE' does not exist after copying." + exit 1 +fi + +log_message "Task Completed!" echo