#!/bin/sh
#
# /etc/kernel/preinst.d intel-microcode script
# Copyright (C) 2012 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
# Released under the GPL v2 or later license
#
# This script makes sure the cpuid module will be loaded before
# the kernel image replaces it.  It is necessary when cpuid is not
# loaded or built-in, IUCODE_TOOL_SCANCPUS=yes is set, and the
# kernel is being upgraded in-place.
#

IUCODE_CONFIG=/etc/default/intel-microcode

IUCODE_TOOL=$(command -v iucode_tool)
if [ -z "${IUCODE_TOOL}" -a -x /usr/sbin/iucode_tool ] ; then
	IUCODE_TOOL=/usr/sbin/iucode_tool
fi

IUCODE_TOOL_SCANCPUS=yes
[ -r ${IUCODE_CONFIG} ] && . ${IUCODE_CONFIG}

if [ -z "${IUCODE_TOOL}" -o "${IUCODE_TOOL_SCANCPUS}" != "yes" ] ; then
	exit
else
	grep -q cpu/cpuid /proc/devices || modprobe cpuid
fi

:
