#!/bin/bash reboot_required="No" n=0 if [ -f /run/reboot-required ]; then n=1 reboot_required="Yes" elif [ -f /var/run/reboot-required ]; then n=2 reboot_required="Yes" else latest_kernel=$(find /boot -maxdepth 1 \( -type f -o -type l \) -name "vmlinuz-*" -printf "%f\n" \ | sort --version-sort \ | tail -n 1) latest_kernel_ver=${latest_kernel#vmlinuz-} if [ -n "$latest_kernel_ver" ]; then n=3 if [ "$(uname -r)" != "$latest_kernel_ver" ]; then reboot_required="Yes" fi fi if [ "$reboot_required" = "No" ] && command -v needrestart >/dev/null 2>&1; then n=4 ksta=$(needrestart -b -k 2>/dev/null | awk -F': ' '/^NEEDRESTART-KSTA/ {print $2}') if [ -n "$ksta" ] && [ "$ksta" != "1" ]; then reboot_required="Yes" fi fi fi echo "Reboot required = ${reboot_required} (${n})" EOF