Skip to content

Instantly share code, notes, and snippets.

@djhunter67
Created February 16, 2023 13:16
Show Gist options
  • Save djhunter67/15ee084a16411c7cacaa12c20583189e to your computer and use it in GitHub Desktop.
Save djhunter67/15ee084a16411c7cacaa12c20583189e to your computer and use it in GitHub Desktop.
Check if a reboot is required on Arch Linux
#!/bin/bash
# Credit: laktak @ https://unix.stackexchange.com/users/46158/laktak
get_boot_kernel() {
local get_version=0
for field in $(file /boot/vmlinuz*); do
if [[ $get_version -eq 1 ]]; then
echo $field
return
elif [[ $field == version ]]; then
# the next field contains the version
get_version=1
fi
done
}
rc=1
libs=$(lsof -n +c 0 2> /dev/null | grep 'DEL.*lib' | awk '1 { print $1 ": " $NF }' | sort -u)
if [[ -n $libs ]]; then
cat <<< $libs
echo "# LIBS: reboot required"
rc=0
fi
active_kernel=$(uname -r)
current_kernel=$(get_boot_kernel)
if [[ $active_kernel != $current_kernel ]]; then
echo "$active_kernel < $current_kernel"
echo "# KERNEL: reboot required"
rc=0
fi
exit $rc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment