From 728feb6ca00204031a441a51fd1170b7db3667a0 Mon Sep 17 00:00:00 2001 From: ChiefGyk3D <19499446+ChiefGyk3D@users.noreply.github.com> Date: Fri, 20 Mar 2026 09:35:01 -0400 Subject: [PATCH 1/2] fix: initialize TEMP_LOG before conditional to prevent unbound variable error When the log file doesn't exist (e.g., fresh installs before unattended-upgrades first runs), TEMP_LOG was only set inside the else branch. The Matrix notification section references TEMP_LOG unconditionally, causing 'TEMP_LOG: unbound variable' crash under set -euo pipefail. Initialize TEMP_LOG="" before the if/else block so grep calls against it safely fail with 2>/dev/null when the log file is absent. --- update-notifier.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/update-notifier.sh b/update-notifier.sh index 433f19c..976fdc3 100755 --- a/update-notifier.sh +++ b/update-notifier.sh @@ -277,6 +277,7 @@ elif [[ "$OS_TYPE" == "rhel" ]]; then fi # Read recent log entries and analyze what happened +TEMP_LOG="" if [[ ! -f "$LOG_FILE" ]]; then log "WARNING: Log file $LOG_FILE not found. Sending notification anyway." LOG_OUTPUT="Log file not found at $LOG_FILE" From 58a1f324e8a04ca8a762ed8a9d47cb663494ff82 Mon Sep 17 00:00:00 2001 From: ChiefGyk3D <19499446+ChiefGyk3D@users.noreply.github.com> Date: Fri, 20 Mar 2026 09:45:18 -0400 Subject: [PATCH 2/2] fix: align notification title/status with actual update availability Three issues fixed: 1. No-log-file case (fresh installs before unattended-upgrades first runs): Previously always showed yellow 'System Update Process Complete' with 'Log file not found' body regardless of available packages. Now checks AVAILABLE_UPDATES and sets status/body accordingly: - Updates available -> updates-available status, lists packages - Nothing available -> no-updates status, 'system is up to date' Both variants append 'No unattended-upgrades history yet (first run)'. 2. Title/status mismatch when security=clean but non-security packages exist: Previously title said 'System Update Check Complete / No updates available' while body said '10 non-security packages available' - contradictory. Added updates-available status promotion: when UPDATE_STATUS==no-updates but AVAILABLE_UPDATES>0, promotes to updates-available. 3. New 'updates-available' status case (orange, 16744272): Title: 'System Updates Available on ' Distinct from 'System Updates Applied' (green) and 'System Update Check Complete' (blue, nothing to do). 4. Matrix section falls back to PLAIN_SUMMARY when no log-parsed content available, ensuring consistent message body across all code paths. --- update-notifier.sh | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/update-notifier.sh b/update-notifier.sh index 976fdc3..45edb17 100755 --- a/update-notifier.sh +++ b/update-notifier.sh @@ -278,11 +278,24 @@ fi # Read recent log entries and analyze what happened TEMP_LOG="" +PLAIN_SUMMARY="" if [[ ! -f "$LOG_FILE" ]]; then log "WARNING: Log file $LOG_FILE not found. Sending notification anyway." - LOG_OUTPUT="Log file not found at $LOG_FILE" - UPDATE_STATUS="unknown" - UPDATE_SUMMARY="Log file not available" + if [[ "$AVAILABLE_UPDATES" -gt 0 ]]; then + UPDATE_STATUS="updates-available" + UPDATE_SUMMARY="${AVAILABLE_UPDATES} non-security package(s) available" + PLAIN_SUMMARY="šŸ“¦ Updates Available: ${AVAILABLE_UPDATES} non-security packages\n Packages: ${AVAILABLE_PACKAGES}" + if [[ "$AVAILABLE_UPDATES" -gt 10 ]]; then + PLAIN_SUMMARY="${PLAIN_SUMMARY}... and $((AVAILABLE_UPDATES - 10)) more" + fi + PLAIN_SUMMARY="${PLAIN_SUMMARY}\nā„¹ļø No unattended-upgrades history yet (first run)" + else + UPDATE_STATUS="no-updates" + UPDATE_SUMMARY="System is up to date" + PLAIN_SUMMARY="āœ… System is up to date\nā„¹ļø No unattended-upgrades history yet (first run)" + fi + LOG_OUTPUT=$(echo -e "$PLAIN_SUMMARY" | python3 -c "import sys, json; print(json.dumps(sys.stdin.read())[1:-1])" 2>/dev/null || \ + echo -e "$PLAIN_SUMMARY" | awk '{gsub(/\\/,"\\\\",$0); gsub(/"/,"\\\"",$0); gsub(/\t/,"\\t",$0); printf "%s ", $0}' | sed 's/[[:cntrl:]]//g') else # Create a snapshot to avoid race conditions with active logging TEMP_LOG=$(mktemp) @@ -429,6 +442,9 @@ else if [[ -z "$HUMAN_SUMMARY" ]]; then HUMAN_SUMMARY="āœ… Update check completed successfully" fi + + # Store plain-text summary for Matrix reuse + PLAIN_SUMMARY="$HUMAN_SUMMARY" # Prepare for JSON (safely escaped) LOG_OUTPUT=$(echo -e "$HUMAN_SUMMARY" | python3 -c "import sys, json; print(json.dumps(sys.stdin.read())[1:-1])" 2>/dev/null || { @@ -447,6 +463,13 @@ if [[ "$UPDATE_STATUS" == "updated" ]] && [[ -z "$UPGRADED_PACKAGE_NAMES" ]] && log "INFO: Corrected status - no packages were actually upgraded this run" fi +# Promote status when non-security updates are available but no security updates applied +if [[ "$UPDATE_STATUS" == "no-updates" ]] && [[ "$AVAILABLE_UPDATES" -gt 0 ]]; then + UPDATE_STATUS="updates-available" + UPDATE_SUMMARY="${AVAILABLE_UPDATES} non-security package(s) available" + log "INFO: Promoting status - ${AVAILABLE_UPDATES} non-security packages available" +fi + # Set notification title and description based on status case "$UPDATE_STATUS" in "updated") @@ -454,6 +477,11 @@ case "$UPDATE_STATUS" in NOTIFICATION_DESC="$UPDATE_SUMMARY at **$LAST_RUN**" NOTIFICATION_COLOR=5814783 # Green ;; + "updates-available") + NOTIFICATION_TITLE="System Updates Available on $HOSTNAME" + NOTIFICATION_DESC="$UPDATE_SUMMARY at **$LAST_RUN**" + NOTIFICATION_COLOR=16744272 # Orange + ;; "no-updates") NOTIFICATION_TITLE="System Update Check Complete on $HOSTNAME" NOTIFICATION_DESC="$UPDATE_SUMMARY at **$LAST_RUN**" @@ -704,9 +732,13 @@ if [[ "$MATRIX_CONFIGURED" == true ]]; then MATRIX_SUMMARY="${MATRIX_SUMMARY}\nāŒ Error: ${ERROR_MSG}" fi - # Default if nothing was found + # Default if nothing was found - fall back to pre-computed summary if [[ -z "$MATRIX_SUMMARY" ]]; then - MATRIX_SUMMARY="āœ… Update check completed successfully" + if [[ -n "$PLAIN_SUMMARY" ]]; then + MATRIX_SUMMARY="$PLAIN_SUMMARY" + else + MATRIX_SUMMARY="āœ… Update check completed successfully" + fi fi MATRIX_LOG=$(echo -e "$MATRIX_SUMMARY")