#!/bin/sh
#
# microcode_ctl:        Update Microcode for P6
#
# chkconfig: 2345 04 99
# description:          Update Microcode for P6 family processors

WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

LOCKFILE=/var/lock/subsys/microcode_ctl
ARGS="-qu"
PROGRAM=/sbin/microcode_ctl
RETVAL=0

# Make sure we are on an intel machine
vendor=`cat /proc/cpuinfo | grep "^vendor_id" | sort -u | awk -F ": " '{ print $2 }'`
[ "$vendor" != "GenuineIntel" ] && return

# Microcode wasn't available until 686's.
family=`cat /proc/cpuinfo | grep "^cpu family" | sort -u | awk -F ": " '{ print $2 }'`
[ $family -lt 6 ] && return

# See how we were called.
case "$1" in
        start|reload|restart|condreload|condrestart)
		/sbin/modprobe microcode
                action "CPU Microcode Update:" $PROGRAM $ARGS
                RETVAL=$?
                # Mark as started regardless of exit status.
                touch "$LOCKFILE"
		/sbin/rmmod microcode
                ;;
        stop|condstop)
                rm -f "$LOCKFILE"
                ;;
        status)
                ;;
        *)
                msg_usage "${0##*/} {start|stop}"
                RETVAL=1
esac

exit $RETVAL
