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.
This commit is contained in:
humocs-man
2026-05-16 09:31:45 +02:00
committed by GitHub
parent ffee5e9471
commit 246e3aa6e1
+10 -5
View File
@@ -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