#!/bin/bash
# intel-ucode-chk.sh
# check microcode update available for this CPU

# $ head /proc/cpuinfo 
# processor       : 0
# vendor_id       : GenuineIntel
# cpu family      : 6
# model           : 79
# model name      : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
# stepping        : 1
# microcode       : 0xb000017

CPU=/proc/cpuinfo
DIR=/lib/firmware/intel-ucode

# fetch values
family=$(grep -P -m1 '^cpu family\t' $CPU | awk '{ print $NF }')
model=$(grep -P -m1 '^model\t' $CPU | awk '{ print $NF }')
stepping=$(grep -P -m1 '^stepping\t' $CPU | awk '{ print $NF }')

# format as 2 digit hex
family=$(printf "%02x" $family)
model=$(printf "%02x" $model)
stepping=$(printf "%02x" $stepping)

# formulate microcode filename, e.g. "06-4f-01"
ucode="$family-$model-$stepping"

# check if microcode file present
if [ -e $DIR/$ucode ] ; then
   [ "$1" != "-q" ] && echo "FOUND: Microcode for this CPU: $DIR/$ucode"
   exit 0
else
   [ "$1" != "-q" ] && echo "Microcode not found for this CPU: $ucode"
   exit 1
fi

