2021-11-01 21:47:18 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# CheckKernel checks if Kernel was updated and not aktivated (rebooted)
|
|
|
|
#
|
|
|
|
# (c) GPL by Ulf Bartholomäus ub1x@gmx.net
|
2021-11-02 20:15:13 +00:00
|
|
|
VERSION="$( basename $0 ) Version 0.2.4 from 02.11.2021"
|
2021-11-01 21:47:18 +00:00
|
|
|
#
|
2021-11-02 20:15:13 +00:00
|
|
|
# Input: 1 parameter optional ("-d" = debug and "-v" = verbose / "-D" = Distro only / "-DV" = Distro and release only / "-K" = running KernelVerion / "-N" = New Kernel Version)
|
2021-11-01 21:47:18 +00:00
|
|
|
# Output: text messages and a kdialog if this is installed
|
|
|
|
# Returnvalue: 0 if Kernel OK and 10 if Kernel is changed
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Changes:
|
2021-11-02 20:15:13 +00:00
|
|
|
# 0.2.4: Change way to collect Distro Name from /etc/os-releas (if empty - provide old info)
|
2021-11-01 21:47:18 +00:00
|
|
|
# 0.2.3: Fix error => update in case only one Kernel is avaialble
|
|
|
|
# 0.2.2: Fix error => new Kernel update: replace initrd with vmlinuz check
|
|
|
|
# 0.2.1: added -D -K and -N option
|
|
|
|
# Fixed error and exit with more than one /boot/initrd-* file
|
|
|
|
# 0.2.0: InitKernel und VmlzKernel entfernt,
|
|
|
|
# [ $( ls -1 /boot/ | grep initrd- | wc -l ) -gt 1 ] && echo "** Error" || ls -1 /boot/ | grep initrd- | cut -d '-' -f 2,3,4
|
|
|
|
# Some small changes and simplifications
|
2021-11-02 20:15:13 +00:00
|
|
|
# 0.1.9: InitKernel erneut angepasstsys
|
|
|
|
# 0.1.8: "==" -> "=" sowie kleinere Shönheitskorrekturen - sowie InitKernel mit awk statt cut
|
2021-11-01 21:47:18 +00:00
|
|
|
# 0.1.7: remove "CheckKernel.sh: Zeile 33: lsb_release: Kommando nicht gefunden."
|
|
|
|
# and => -d = debaug
|
|
|
|
# 0.1.6: if "lsb_release" not available use "cat /etc/*-release" info
|
2021-11-02 20:15:13 +00:00
|
|
|
# 0.1.5: Fix trouble if InitKernel is empty
|
2021-11-01 21:47:18 +00:00
|
|
|
# 0.1.4: Fix some errors
|
|
|
|
# 0.1.3: Fix running and new kernel are equal but shown as different
|
|
|
|
# 0.1.2: Remove "initrd-" from InitKernel
|
|
|
|
# 0.1.1: Add Kernel Info in kdialog
|
|
|
|
# 0.1.0: exchange some direct calls against definition
|
|
|
|
# add check if new Kernel is in GRUB Config file
|
|
|
|
# 0.0.7: read Kernel version from menu.lst
|
|
|
|
# 0.0.6: add verbose mode
|
|
|
|
# 0.0.5: syslog messages
|
|
|
|
# 0.0.4: returnvalue if Kernel is changed is 10
|
|
|
|
# 0.0.3: hostname in kdialog title
|
|
|
|
# 0.0.2: kdialog output
|
|
|
|
# 0.0.1: generation
|
|
|
|
#
|
|
|
|
|
2021-11-02 20:15:13 +00:00
|
|
|
DEBUG="" # Debug mode ="1"
|
|
|
|
MyDistro="" # Name of the Distro
|
|
|
|
MyDstVer="" # Distro Version info
|
|
|
|
MyKernel="" # Running Kernel Version
|
|
|
|
InitKernel="" # Newest Kernel at initrd
|
2021-11-01 21:47:18 +00:00
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "-d" ] ; then
|
|
|
|
DEBUG="1"
|
|
|
|
echo -e "\t<${VERSION}>"
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
|
2021-11-02 20:15:13 +00:00
|
|
|
if [ -e /etc/os-release ]; then
|
|
|
|
MyDistro="$( grep PRETTY_NAME /etc/os-release )"
|
|
|
|
MyDistro="${MyDistro/*=\"/}" # remove first string till ="
|
|
|
|
MyDistro="${MyDistro/\"*/}" # remove "
|
|
|
|
MyDstVer="$( grep VERSION_ID /etc/os-release )"
|
|
|
|
MyDstVer="${MyDstVer/*=\"/}" # remove first string till ="
|
|
|
|
MyDstVer="(${MyDstVer/\"*/})" # remove "
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "${MyDistro}" ] && [ -e /proc/version ]; then
|
|
|
|
MyDistro="$( cat /proc/version )"
|
|
|
|
MyDistro="${MyDistro/*;/}" # remove first string till ";"
|
|
|
|
MyDistro="${MyDistro/)*/}" # remove anything behind ")"
|
|
|
|
MyDistro="${MyDistro/# /}" # remove blanks in the beginning
|
|
|
|
echo -n "Version ${MyDistro} | "
|
|
|
|
fi
|
2021-11-01 21:47:18 +00:00
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "-D" ] ; then
|
|
|
|
echo "${MyDistro}"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2021-11-02 20:15:13 +00:00
|
|
|
if [ $# -gt 0 ] && [ "$1" = "-DV" ] ; then
|
|
|
|
echo "${MyDistro} ${MyDstVer}"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "-V" ] ; then
|
|
|
|
echo "${MyDstVer}"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2021-11-01 21:47:18 +00:00
|
|
|
MyKernel="$( uname -r )"
|
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "-K" ] ; then
|
|
|
|
echo "${MyKernel}"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
InitKernel="$( ls -1tr /boot/ | grep 'vmlinuz-' )"
|
2021-11-02 20:15:13 +00:00
|
|
|
if [ -n "${InitKernel}" ] ; then
|
|
|
|
InitKernel="${InitKernel/*vmlinuz-/}"
|
2021-11-01 21:47:18 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $# -gt 0 ] && [ "$1" = "-N" ] ; then
|
2021-11-02 20:15:13 +00:00
|
|
|
echo "${InitKernel}"
|
2021-11-01 21:47:18 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2021-11-02 20:15:13 +00:00
|
|
|
if [ "${MyKernel}" = "${InitKernel}" ] ; then
|
2021-11-01 21:47:18 +00:00
|
|
|
if [ $# -gt 0 ] && [ "$1" = "-v" ] ; then
|
2021-11-02 20:15:13 +00:00
|
|
|
echo -e "\t*** $( date "+%X / %d.%m.%Y" ) \tDistro: ${MyDistro} ${MyDstVer} \tKernel: ${MyKernel} \t*** Kernel OK ***"
|
2021-11-01 21:47:18 +00:00
|
|
|
else
|
|
|
|
echo "*** Kernel OK (${MyKernel})";
|
|
|
|
fi
|
|
|
|
else
|
2021-11-02 20:15:13 +00:00
|
|
|
if ( [ $# -gt 0 ] && [ "$1" = "-v" ] ) ; then
|
|
|
|
echo -e "\t*** $( date "+%X / %d.%m.%Y" ) \tDistro: ${MyDistro} ${MyDstVer} \tKernel: ${MyKernel} \t*** NEW Kernel ${InitKernel}!!! ***"
|
2021-11-01 21:47:18 +00:00
|
|
|
else
|
2021-11-02 20:15:13 +00:00
|
|
|
MsgTxt="*** Kernel Updated from ${MyKernel} to ${InitKernel}! => please reboot"
|
2021-11-01 21:47:18 +00:00
|
|
|
echo "${MsgTxt}";
|
|
|
|
logger -t $( basename $0 ) "${MsgTxt}"
|
|
|
|
if [ $# -eq 0 ] && [ -e $( which kdialog 2>> /dev/null ) ] ; then
|
|
|
|
kdialog --title "*** $( hostname ) ***" --error "${MsgTxt}" >> /dev/null 2>> /dev/null
|
|
|
|
fi
|
|
|
|
fi
|
2021-11-02 20:15:13 +00:00
|
|
|
exit 10
|
2021-11-01 21:47:18 +00:00
|
|
|
fi
|