Check if a reboot is neccessary

So it’s basically just a list of packages that need reboot after an update? Well, that’s a bit disappointing. But it makes it easy to check in a script.

This script will tell you whether reboot is necessary, with approximately the same accuracy as eos-update-notifier:

#!/bin/bash
# Check whether reboot is necessary after an update.
# dependency: checkupdates
UPDATES=$(checkupdates)
# assume packages containing these strings in name need reboot after updating
REBOOT="(ucode|cryptsetup|linux|nvidia|mesa|systemd|wayland|xf86-video|xorg)"

if [[ $UPDATES =~ $REBOOT ]]; then
  echo "Needs reboot"
  exit 0;
fi
echo "No reboot needed"
exit 1

EDIT: here is a much shorter script that does (almost) the same thing (just in case someone complains about inefficiency):

checkupdates | awk '/ucode/ || /cryptsetup/ || /linux/ || /nvidia/ || /mesa/ || /systemd/ || /wayland/ || /xf86-video/ || /xorg/ { print "Needs reboot."; exit }'

EDIT 2: simplified the code in the first example.

5 Likes