40 lines
1.3 KiB
Plaintext
40 lines
1.3 KiB
Plaintext
kernel_func () {
|
|
distro="$(awk -F= '/^ID/ {print $NF}' /etc/os-release)"
|
|
if [[ "${distro}" == arch ]]
|
|
then
|
|
package="$(pacman -Q \
|
|
| grep -vE -- '-(firmware|api|keyring|linux|docs|headers)' \
|
|
| grep linux | awk '{print $1}')"
|
|
current_kernel=$(uname -r)
|
|
next_kernel="$(pacman -Q | grep "${package}" \
|
|
| awk '{print $NF}' | tail -1 | tr -d '\n')"
|
|
current_ucode=$(awk -F'[[:space:]]*:[[:space:]]*' '/microcode/ {print $2}' /proc/cpuinfo | uniq)
|
|
if whence iucode_tool &> /dev/null
|
|
then
|
|
next_ucode=$(iucode_tool -lqS /lib/firmware/intel-ucode/ | grep -Po 'rev 0x\d+' | tr -d '[rev ]' | tail -1)
|
|
fi
|
|
if [[ "${current_kernel}" =~ ${next_kernel} ]]
|
|
then
|
|
if [[ -n "${next_ucode}" ]] && [[ "${current_ucode}" == ${next_ucode} ]] || [[ -z ${intel_ucode} ]];
|
|
then
|
|
print -P "[%F{#00ff00}OK%f]"
|
|
else
|
|
print -P "[%F{yellow}needs reboot%f]"
|
|
fi
|
|
else
|
|
print -P "[%F{yellow}needs reboot%f]"
|
|
fi
|
|
elif [[ "${distro}" == debian ]]
|
|
then
|
|
current_kernel="$(uname -v | awk '{print $5}')"
|
|
next_kernel="$(dpkg -l | grep -P '^ii\s+linux-image' | awk '{print $3}' \
|
|
| sort -Vu | tail -1)"
|
|
if [[ "${current_kernel}" == ${next_kernel} ]]
|
|
then
|
|
print -P "[%F{#00ff00}OK%f]"
|
|
else
|
|
print -P "[%F{yellow}needs reboot%f]"
|
|
fi
|
|
fi
|
|
}
|