tags 571408 patch
user ubuntu-de...@lists.ubuntu.com
usertags 571408 maverick ubuntu-patch
thanks

*** /tmp/tmpgh8363
In Ubuntu, we've applied the attached patch to achieve the following:

  [ Daniel J Blueman ]
  * Rewrote update-intel-microcode script to robustly parse and
    download updated microcode correctly (LP: #569488)

  [ Stefano Rivera ]
  * update-intel-microcode: Do not eval() code from the Internet, and use
    Python's built in tarfile library rather than a temporary directory.
  * debian/microcode.ctl.init: Depend on $remote_fs.

We thought you might be interested in doing the same. 

I made the change depend on Python 2.6, as that's currently the ubuntu
default version in sid (still finishing up the transition). You could
add 2.5 support with the following:
Depends: python, python (>= 2.6) | python-simplejson

and:
-import json
+try:
+    import json
+except ImportError:
+    improt simplejson as json

SR

-- 
Stefano Rivera
  http://tumbleweed.org.za/
  H: +27 21 465 6908 C: +27 72 419 8559  UCT: x3127
diff -u microcode.ctl-1.17/debian/update-intel-microcode microcode.ctl-1.17/debian/update-intel-microcode
--- microcode.ctl-1.17/debian/update-intel-microcode
+++ microcode.ctl-1.17/debian/update-intel-microcode
@@ -1,75 +1,55 @@
-#!/bin/sh
-# Copyright (c) 2008 by Giacomo A. Catenazzi <c...@debian.org>
-# This file is licensed with GPL version 2 (or at your option any later versions)
-# For the full license, see http://fsf.org
-
-set -e
-
-# This script will download and update the Intel microcode
-
-# Check wget
-if ! which wget > /dev/null 2> /dev/null; then
-    echo "wget not found. Please install wget" 1>&2
-    exit 1
-fi
-if ! grep -sq GenuineIntel /proc/cpuinfo; then
-    echo "microcode.ctl: Yet we provide only microcodes for Intel processors" 1>&2
-    echo "Your CPU seems not an Intel processor" 1>&2
-    exit 1
-fi
-
-REMOTE_RSS='http://feeds.downloadcenter.intel.com/rss/?p=483&lang=eng'
-REMOTE_DATA="$(wget -t 2 -T 20 -nv -q -O - "$REMOTE_RSS" | perl -pe 's|^.+?<IntelDC:Type>Firmware</IntelDC:Type><IntelDC:Version>(20[0-9]*)</IntelDC:Version><IntelDC:Status>latest</IntelDC:Status>.+?<IntelDC:FileURL>([^<]*\1[^<]*)</IntelDC:FileURL>.*$|\1 \2\n|' - || echo 'ERROR')"
-if [ "0$REMOTE_DATA" = "0"  -o  "0$REMOTE_DATA" = "0ERROR" ] ; then
-    echo "Error: could not find remote data in $REMOTE_RSS" 1>&2
-    echo "...exiting" 1>&2
-    exit 1
-fi
-REMOTE_FILE=$(echo $REMOTE_DATA | sed -ne 's#^\(.*\) \(http://.*\)$#\2#p' -)
-REMOTE_DATE=$(echo $REMOTE_DATA | sed -ne 's#^\(.*\) \(http://.*\)$#\1#p' -)
-
-LOCAL_DIR=/usr/share/misc
-LOCAL_FILE="$LOCAL_DIR/intel-microcode.dat"
-
-if [ -f "$LOCAL_FILE" ] ; then
-    LOCAL_DATE=$(sed -ne 's#^/\*\(.*\)\*/.*$#\1#p' "$LOCAL_FILE" | head -n 1 | date "+%Y%m%d" -f - )
-    echo "Local version: $LOCAL_DATE"
-    echo "Remote version: $REMOTE_DATE"
-
-    if [ "0$REMOTE_DATE" = "0" ] ; then
-	echo "could not extract the actual data of remote microcode"
-	exit 1
-    elif [ "0$REMOTE_DATE" -le "0$LOCAL_DATE" ] ; then
-	echo "No need to download a new microcode" 1>&2
-	exit 0
-    fi
-else
-    echo "Local version: (none)"
-    echo "Remote version: $REMOTE_DATE"
-fi
-
-echo "Downloading a new version of microcode."
-
-case "$REMOTE_FILE" in
-    *.tgz | *.tar.gz )	FILTER=" tar xzOf - " ;;
-    *.dat.gz )		FILTER=" gzip -cd " ;;
-    * )			FILTER=" cat - " ;;
-esac
-
-
-if wget -t 2 -T 20 -nv -q -O - "$REMOTE_FILE" | $FILTER > "$LOCAL_FILE".tmp ; then
-    mv "$LOCAL_FILE".tmp "$LOCAL_FILE"
-    echo "microcode downloaded sucessfully" 1>&2
-else
-    echo "Error on downloading the microcode." 1>&2
-    echo "Install microcode manually. (See /usr/share/doc/microcode.ctl/README.Debian)" 1>&2
-    exit 1
-fi
-
-# load the new microcode
-
-
-if [ "-$1" != "--no-reload" ] ; then
-    /etc/init.d/microcode.ctl reload
-fi
+#!/usr/bin/python
+# download latest Intel processor microcode
+# (c) 2010: Daniel J Blueman, Stefano Rivera
+# GPL v3 license [http://fsf.org/]
+
+import json
+import os
+from StringIO import StringIO
+import sys
+import tarfile
+import urllib2
+
+url = 'http://downloadcenter.intel.com/JSONDataProvider.aspx?DownloadType=Firmware&ProductFamily=Processors&ProductLine=Desktop&ProductProduct=Intel%C2%AE%20Core%E2%84%A2%20i7%20Processor&sortDir=descending&Hits=10&&lang=eng&pg=1&refresh=filters&dataType=json&type=GET'
+try:
+	data = urllib2.urlopen(url).read()
+except urllib2.HTTPError, e:
+	print 'failed to download microcode index - %s' % e.code
+	sys.exit(1)
+except urllib2.URLError, e:
+	print 'failed to download microcode index - %s' % e.reason
+	sys.exit(1)
+
+results = json.loads(data)['results']
+
+# check for numerically highest date
+newest = sorted(results, key=lambda x: x['version'])[-1]
+
+srcurl = 'http://downloadmirror.intel.com/%s/eng/microcode-%s.tgz' % (newest['title']['downloadid'], newest['version'])
+
+try:
+	src = urllib2.urlopen(srcurl)
+except urllib2.HTTPError, e:
+	print 'failed to download microcode from %s - %s' % (srcurl, e.code)
+	sys.exit(1)
+except urllib2.URLError, e:
+	print 'failed to download microcode from %s - %s' % (srcurl, e.reason)
+	sys.exit(1)
+
+tar = tarfile.open(mode='r:gz', fileobj=StringIO(src.read()))
+
+datname = 'microcode-%s.dat' % newest['version']
+src = tar.extractfile(datname)
+
+dstpath = '/usr/share/misc/intel-microcode.dat'
+
+try:
+	dst = file(dstpath, 'w')
+	dst.write(src.read())
+	dst.close()
+	os.chown(dstpath, 0, 0)
+except OSError, e:
+	print 'failed to install microcode to %s - %s' % (dstpath, e.strerror)
+	sys.exit(1)
 
+print 'successfully downloaded Intel %s microcode' % newest['version']
diff -u microcode.ctl-1.17/debian/microcode.ctl.init microcode.ctl-1.17/debian/microcode.ctl.init
--- microcode.ctl-1.17/debian/microcode.ctl.init
+++ microcode.ctl-1.17/debian/microcode.ctl.init
@@ -5,10 +5,8 @@
 
 ### BEGIN INIT INFO
 # Provides:          microcode.ctl
-# Required-Start:    $local_fs
-# Required-Stop:     $local_fs
-# Should-Start:      $remote_fs
-# Should-Stop:       $remote_fs
+# Required-Start:    $remote_fs
+# Required-Stop:     $remote_fs
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: Load Intel microcode on CPU
diff -u microcode.ctl-1.17/debian/microcode.ctl.postinst microcode.ctl-1.17/debian/microcode.ctl.postinst
--- microcode.ctl-1.17/debian/microcode.ctl.postinst
+++ microcode.ctl-1.17/debian/microcode.ctl.postinst
@@ -3,7 +3,6 @@
 #
 # see: dh_installdeb(1)
 
-
 set -e
 
 . /usr/share/debconf/confmodule
@@ -44,9 +43,9 @@
 
 	db_get microcode.ctl/check-new
 	if [ "$RET" = true ] ; then
-	    update-intel-microcode --no-reload 1>&2 || true
+	    update-intel-microcode 1>&2 || true
 	else
-	    echo "You have choose not to check for new microcoded. To change" 1>&2
+	    echo "You have choose not to check for new microcode. To change" 1>&2
 	    echo 'run  "dpkg-reconfigure -plow microcode.ctl"' 1>&2
 	fi
 
@@ -69 +67,0 @@
-
diff -u microcode.ctl-1.17/debian/update-intel-microcode.8 microcode.ctl-1.17/debian/update-intel-microcode.8
--- microcode.ctl-1.17/debian/update-intel-microcode.8
+++ microcode.ctl-1.17/debian/update-intel-microcode.8
@@ -1,32 +1,25 @@
-.TH MICROCODE_CTL "8" "17 May 2007" "update-intel-microcode"
+.TH MICROCODE_CTL "8" "12 May 2010" "update-intel-microcode"
 .SH NAME
-update-intel-microcode \- check and download new intel microcode
+update-intel-microcode \- download current Intel processor microcode
 .SH SYNOPSIS
 .B update-intel-microcode
-[\fI\--no-reload\fR]
 .br
 .SH DESCRIPTION
 .PP
-The update-intel-microcode is a script that check if there is a new
-microcode data for the Intel CPU.  Eventually it downloads, installs
-and loads the new microcode data, used by the microcode_ctl(8)
-utility.  There is an optional argument:
-.br
-.PP
-\fB--no-reload\fR After installing the microcode, it dosn't try to
-load the new microcode in the CPU.
+The update-intel-microcode is a script that downloads the current
+microcode for Intel processors, installing it on the filesystem.
 .PD
 .SH EXAMPLE
 .TP
 update-intel-microcode
-checks, and eventually downloads, installs and loads a new microcode.
+downloads and installs the current Intel processor microcode.
 .SH FILES
 .TP
 /usr/share/misc/intel-microcode.dat
 The default microcode location
 .PD
 .SH AUTHOR
-This utility is written by Giacomo Catenazzi for Debian.
+This utility is written by Daniel J Blueman for Debian.
 .br
 .SH "SEE ALSO"
 .BR microcode_ctl (8)
diff -u microcode.ctl-1.17/debian/control microcode.ctl-1.17/debian/control
--- microcode.ctl-1.17/debian/control
+++ microcode.ctl-1.17/debian/control
@@ -8,7 +8,7 @@
 
 Package: microcode.ctl
 Architecture: i386 amd64
-Depends: module-init-tools, udev | makedev (>> 2.3.1-53),
+Depends: module-init-tools, udev | makedev (>> 2.3.1-53), python (>= 2.6),
  ${misc:Depends}, ${shlibs:Depends}
 Recommends: wget, intel-microcode
 Replaces: microcode-ctl
diff -u microcode.ctl-1.17/debian/changelog microcode.ctl-1.17/debian/changelog

Attachment: signature.asc
Description: Digital signature

Reply via email to