Refactor to be a bit more modular

This commit is contained in:
2026-03-11 14:15:40 -04:00
parent 601954fe7c
commit f5c6d28095
2 changed files with 47 additions and 15 deletions

View File

@@ -1,13 +1,39 @@
kernel_func () {
machine_id=$(cat /etc/machine-id)
current_kernel=$(uname -r)
current_ucode=$(awk -F'[[:space:]]*:[[:space:]]*' '/microcode/ {print $2}' /proc/cpuinfo | uniq)
[[ -f /run/next_kernel ]] && next_kernel="$(sudo cat /run/next_kernel)"
next_ucode=$(iucode_tool -lqS /lib/firmware/intel-ucode/ | grep -Po 'rev 0x\d+' | tr -d '[rev ]' | tail -1)
if [[ "${current_kernel}" == ${next_kernel} ]] && [[ "${current_ucode}" == ${next_ucode} ]] || [[ -z "${next_kernel}" ]]
distro="$(awk -F= '/^ID/ {print $NF}' /etc/os-release)"
if [[ "${distro}" == arch ]]
then
print -P "[%F{#00ff00}OK%f]"
else
print -P "[%F{yellow}needs reboot%f]"
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} ]]
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
}