Skip to content

Instantly share code, notes, and snippets.

@CodaBool
Last active June 20, 2026 05:25
Show Gist options
  • Select an option

  • Save CodaBool/470996bd920cfaedcb2bd94331c49df5 to your computer and use it in GitHub Desktop.

Select an option

Save CodaBool/470996bd920cfaedcb2bd94331c49df5 to your computer and use it in GitHub Desktop.
Restart checker for immutable distros

Checks if a NVIDIA driver is staged, if so will send a notification

KDE

nano $HOME/Documents/reboot_check.sh

#!/usr/bin/env bash
set -u

reasons=()

if command -v rpm-ostree >/dev/null 2>&1; then
  rpm-ostree status --pending-exit-77 >/dev/null 2>&1
  [[ $? -eq 77 ]] &&
    reasons+=("A new system deployment is staged.")
fi

if command -v nvidia-smi >/dev/null 2>&1 &&
   command -v flatpak >/dev/null 2>&1; then
  host_version="$(
    nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null |
      head -n1 | tr -d '[:space:]'
  )"

  if [[ -n "$host_version" ]]; then
    required_version="${host_version//./-}"
    installed_versions="$(
      flatpak list --columns=application 2>/dev/null |
        sed -nE 's/^org\.freedesktop\.Platform\.GL(32)?\.nvidia-//p' |
        sort -u
    )"

    if [[ -n "$installed_versions" ]] &&
       ! grep -qx "$required_version" <<<"$installed_versions"; then
      reasons+=(
        "NVIDIA driver $host_version is running, but its matching Flatpak runtime is not installed."
      )
    fi
  fi
fi

if ((${#reasons[@]})); then
  body="$(printf '• %s\n' "${reasons[@]}")"
  kdialog --title "Restart recommended" \
    --passivepopup "$body" 15 >/dev/null 2>&1
  exit 1
fi

kdialog --title "Restart check complete" \
  --passivepopup "No restart is currently needed." 10 >/dev/null 2>&1

GNOME

#!/usr/bin/env bash
set -u

reasons=()

if command -v rpm-ostree >/dev/null 2>&1; then
  rpm-ostree status --pending-exit-77 >/dev/null 2>&1
  [[ $? -eq 77 ]] &&
    reasons+=("A new system deployment is staged.")
fi

if command -v nvidia-smi >/dev/null 2>&1 &&
   command -v flatpak >/dev/null 2>&1; then
  host_version="$(
    nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null |
      head -n1 | tr -d '[:space:]'
  )"

  if [[ -n "$host_version" ]]; then
    required_version="${host_version//./-}"
    installed_versions="$(
      flatpak list --columns=application 2>/dev/null |
        sed -nE 's/^org\.freedesktop\.Platform\.GL(32)?\.nvidia-//p' |
        sort -u
    )"

    if [[ -n "$installed_versions" ]] &&
       ! grep -qx "$required_version" <<<"$installed_versions"; then
      reasons+=(
        "NVIDIA driver $host_version is running, but its matching Flatpak runtime is not installed."
      )
    fi
  fi
fi

if ((${#reasons[@]})); then
  body="$(printf '• %s\n' "${reasons[@]}")"
  notify-send --app-name="Restart Check" --urgency=critical \
    --icon=system-reboot "Restart recommended" "$body"
  exit 1
fi

notify-send --app-name="Restart Check" --urgency=normal \
  --icon=emblem-default "Restart check complete" \
  "No restart is currently needed."

Timers

let's not run these manually. Since updates run automatically 15 minutes after boot we'll run these notifications 18 minutes after boot

write this as a user .service and user .timer

  1. chmod +x $HOME/Documents/reboot_check.sh
  2. mkdir -p $HOME/.config/systemd/user/
  3. nano $HOME/.config/systemd/user/reboot_check.timer
[Unit]
Description=Run reboot check after boot

[Timer]
OnBootSec=18min
Unit=reboot_check.service
Persistent=false

[Install]
WantedBy=timers.target
  1. nano $HOME/.config/systemd/user/reboot_check.service
[Unit]
Description=Check whether a reboot is needed

[Service]
Type=oneshot
ExecStart=%h/Documents/reboot_check.sh
  1. systemctl --user enable --now reboot_check.timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment