From 246e3aa6e188aa6a9e91e9a298f7e268ed1f212f Mon Sep 17 00:00:00 2001 From: humocs-man <251756307+humocs-man@users.noreply.github.com> Date: Sat, 16 May 2026 09:31:45 +0200 Subject: [PATCH] Refactor bootc user notification script Updated status check to explicitly verify 'staged: null' for current system status. Adjusted notification logic to handle user context correctly. --- scripts/notify-bootc-user.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/notify-bootc-user.sh b/scripts/notify-bootc-user.sh index 45099ee..372a839 100755 --- a/scripts/notify-bootc-user.sh +++ b/scripts/notify-bootc-user.sh @@ -1,5 +1,5 @@ #!/bin/bash - +set -euo pipefail # Pfade BOOTC="/usr/bin/bootc" LOGGER="/usr/bin/logger" @@ -14,17 +14,24 @@ TAG="bootc-timer" $BOOTC upgrade # 2. Status-Check -if $BOOTC status --json | grep -q '"staged"'; then - +# PRÜFUNG ANGEPASST: Wir prüfen, ob der Status EXPLIZIT 'staged: null' enthält. +# Wenn dies der Fall ist, bedeutet es "System aktuell". +if $BOOTC status --json | grep -q '"staged": null"'; then + # KEIN Update gefunden (Status ist null) + $LOGGER -t "$TAG" "System aktuell (keine Updates vorhanden)." +else + # Ein Update ist gestaged oder der Status ist nicht null. Wir senden die Benachrichtigung. + # 3. Den ersten User finden, der nicht Root ist USER_ID=$($LOGINCTL list-users --no-legend | awk '$2 != "root" {print $1; exit}') if [[ -z "$USER_ID" ]]; then + # Update bereit, aber kein aktiver Desktop-User gefunden. Protokollieren und beenden. $LOGGER -t "$TAG" "Update bereit, aber kein aktiver Desktop-User gefunden." exit 0 fi - # 4. Benachrichtigung senden + # 4. Benachrichtigung senden (Im Kontext des Benutzers) ACTION=$($SUDO -u "#$USER_ID" env \ DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USER_ID/bus \ XDG_RUNTIME_DIR=/run/user/$USER_ID \ @@ -40,6 +47,4 @@ if $BOOTC status --json | grep -q '"staged"'; then $LOGGER -t "$TAG" "User hat Reboot gewählt." $SYSTEMCTL reboot fi -else - $LOGGER -t "$TAG" "System aktuell." fi