#!/bin/sh

# Copyright 2018 by Dell EMC.
# All rights not expressly granted herein are reserved.
# Created in the United States of America.
#
# This digital media is protected by U.S. and international copyright and
# intellectual property laws. Unless otherwise specified, all information
# and screens appearing as part of this digital medium, including
# software, services, documents, text, images, icons, and logos design;
# the selection, assembly, arrangement, and design thereof; and the code
# that enables its presentation, are the sole property of Dell EMC.
#
# Except as otherwise required by applicable law, no part of any
# copyrighted material may be reproduced, modified, translated,
# distributed, published, or transmitted by any means, electronic or
# mechanical, for any purpose, without the prior written consent of Dell EMC.

command="/usr/sbin/cpucontrol"
LOGGER="/usr/bin/logger"
ucode_location="/usr/share/isi_ucode"

if [ ! -x ${command} ]
then
	${LOGGER} -s "An executable \"${command}\" not found"
	exit 1
fi

if [ ! -d ${ucode_location} ]
then
	${LOGGER} -s "Microcode directory \"${ucode_location}\" not found"
	exit 1
fi

for cpu in `/bin/ls -1 /dev/cpuctl*`
do
	echo "Attempting microcode update & enabling Spectre 2 fix for ${cpu}"
	${command} -vvv -d ${ucode_location} -u ${cpu}
	${command} -S ${cpu}
done 2>&1 | ${LOGGER} -s

echo "Current value of" `/sbin/sysctl machdep.spectre2fix.level` | ${LOGGER} -s
