Some system updates will require you to restart your system. Packages includes microcode, kernel, driver, xorg and systemd as likely candidates. Below is a list of packages which may warrent a system restart. If you can think of other packages to include in the check just add the package(s) to the $reboot regex in the script.
ucode
cryptsetup
linux
nvidia
mesa
systemd
wayland
xf86-video
xorg
Utility script
The script calls the checkupdates script - and yay if installed - and uses regular expression to suggest a possible system restart.
#!/usr/bin/env bash
reboot="(ucode|cryptsetup|linux|nvidia|mesa|systemd|wayland|xf86-video|xorg)"
if [[ $(which yay) =~ (yay) ]]; then
updates=$(checkupdates; yay -Qua)
else
updates=$(checkupdates)
fi
echo "$updates"
if [[ $updates =~ $reboot ]]; then
echo "Updating possibly requires system restart ..."
fi
Usage
As noted in comments the check is very broad and not intended by any means to be authoritative - it only serves the purpose of suggesting - before updates are installed - if system restart could be necessary.
Credit and inspiration
Inspiration from @Kresimir and EndeavourOS forum [1] [2] and the resulting script [3]
After I updated those packages, the script prints nothing.
However, needrestart (available in the community repo) tells me:
Scanning processes...
Scanning candidates...
Scanning processor microcode...
Scanning linux images...
Running kernel seems to be up-to-date.
The processor microcode seems to be up-to-date.
No services need to be restarted.
No containers need to be restarted.
User sessions running outdated binaries:
gdm @ session #1: gdm-x-session[986]
yochanan @ session #3: gdm-x-session[1349]
#!/bin/bash
#/etc/pacman.d/hooks.bin/reboot.sh
pkgsboot="${1}"
declare -a packages=($(cat -)) # all packages in pacman transaction
for package in "${packages[@]}"; do
if [[ "$package" =~ $pkgsboot ]]; then
echo "Updating possibly requires system restart ($package)"
#exit 0 # can comment this line or not ...
fi
done
note: hooks are sorted by name, so prefer a name like zreboot.hook
script with “linux” is not exact we a lot of “**linux**”
and also here linux-** is too big as xorg …
for: linux-* , xorg-*
we would need a list of complicated regex, and pamac runs on arm and archlinux .
ps: exists also a “simple” pacman hook but much less flexible
I have also some script for find errors and .pacnew after update (read pacman.log)
# find last warnings chmod in log
# warning.*permissions differ
# find permissions differ in log
# usage pacnewsListLog "2018-06"
permissionsListLog()
{
declare -a line
declare -A results
declare d=${1:-$(date +%Y-%m)} # monthly logs, day: -%d
declare d=${1:-$(date +%Y-%m-%d)} # current day
while read -ra line ; do
if [ -d "${line[-1]}" ]; then
results["${line[-1]}"]=1 # uniqu
fi
done < <(grep -E "${d}.*warning.*permissions differ" /var/log/pacman.log)
if [[ "${#results[@]}" > 0 ]] ; then
echo ""
for dir in "${!results[@]}"; do
#echo -en "\t${dir} "
echo -e "\t$(pacman -Qo "${dir}")"
done
#printf "\t%s\\n" "${!results[@]}"
echo -e "${c_re}::${c_r} Your system configuration is no longer up to date ?"
echo -e "${c_re}::${c_r} change by chmod permissions"
fi
}
permissionsListLog
# find .pacnew in log
# usage pacnewsListLog "2018-06"
pacnewsListLog()
{
declare -a line
declare -A results
declare d=${1:-$(date +%Y-%m)} # by default monthly files, day: -%d
while read -ra line ; do
#echo "${line[-1]}"
if [ -f "${line[-1]}" ]; then
results["${line[-1]}"]=1 # uniqu
fi
done < <(grep -E "${d}.*warning.*\.pacnew$" /var/log/pacman.log)
if [[ "${#results[@]}" > 0 ]] ; then
echo ""
printf "\t%s\\n" "${!results[@]}"
echo -e "${c_re}::${c_r} Your system configuration is no longer up to date"
fi
}
# find last pacsave in log
pacnewsListLog