Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shaked8634/fd23ea4c8ec611faa206e87a460d6233 to your computer and use it in GitHub Desktop.
Save shaked8634/fd23ea4c8ec611faa206e87a460d6233 to your computer and use it in GitHub Desktop.
Pacman script to notify if kernel requires restart is required after upgrade (replace '_' with '/' in filenames)
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
Description = Checking if kernel requires restart
When = PostTransaction
Exec = /usr/local/bin/check_running_kernel.sh
#!/bin/env bash
LINUX=$(uname -r)
if [[ "$LINUX" == *-lts ]]; then
installed_ver=$(pacman -Q linux-lts | awk '{print $NF}')-lts
else
installed_ver=$(pacman -Q linux | awk '{print $NF}' | rev | sed 's/\./-/' | rev)
fi
if [[ $installed_ver != "$LINUX" ]]; then
socket=$(ls /tmp/.X11-unix/* | head -n 1)
display=":$(ls $socket | sed 's#/tmp/.X11-unix/X##' | head -n 1)"
user=$(stat -c %U /tmp/.X11-unix/X0)
uid=$(id -u $user)
command="DISPLAY=$display DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus notify-send \"$LINUX kernel was upgrade\". \"System requires restart\""
doas -u $user sh -c "$command"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment