pciutils (1:3.1.7-6) 04-update-pciids.sh.patch

Summary

 update-pciids.sh |  165 ++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 110 insertions(+), 55 deletions(-)

    
download this patch

Patch contents

--- a/update-pciids.sh	2008-11-11 10:11:51.000000000 +1100
+++ b/update-pciids.sh	2010-01-27 14:51:06.000000000 +1100
@@ -1,75 +1,130 @@
 #!/bin/sh
 
-[ "$1" = "-q" ] && quiet=true || quiet=false
+# update-pciids.sh is licensed under the GNU General Public License
+# (GPL) version 2 or above.
+# 
+# Copyright (C) 2008-2010 Anibal Monsalve Salazar <anibal@debian.org>
+# 
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# Please read the "COPYING" file in the archive root, or visit
+# http://www.gnu.org/licenses/gpl.html, for information about the GPL.
+#
+# This scipt is a rewrite of a script with the same name by
+# Martin Mares.
 
 set -e
-SRC="http://pciids.sourceforge.net/v2.2/pci.ids"
-DEST=pci.ids
-PCI_COMPRESSED_IDS=
-GREP=grep
-
-# if pci.ids is read-only (because the filesystem is read-only),
-# then just skip this whole process.
-if ! touch ${DEST} >/dev/null 2>&1 ; then
-	${quiet} || echo "${DEST} is read-only, exiting." 1>&2
-	exit 1
-fi
-
-if [ -n "$PCI_COMPRESSED_IDS" ] ; then
-	DECOMP="cat"
-	SRC="$SRC.gz"
-	GREP=zgrep
-elif which bzip2 >/dev/null 2>&1 ; then
-	DECOMP="bzip2 -d"
-	SRC="$SRC.bz2"
-elif which gzip >/dev/null 2>&1 ; then
-	DECOMP="gzip -d"
-	SRC="$SRC.gz"
+
+#URL="http://pci-ids.ucw.cz/pci.ids"
+URL="http://pciids.sourceforge.net/v2.2/pci.ids"
+FILE="pci.ids"
+
+RM="/bin/rm"
+MV="/bin/mv"
+SED="/bin/sed"
+GREP="/bin/grep"
+ECHO="/bin/echo"
+CHMOD="/bin/chmod"
+CHOWN="/bin/chown"
+GUNZIP="/bin/gunzip"
+BUNZIP2="/bin/bunzip2"
+TOUCH="/usr/bin/touch"
+WGET="/usr/bin/wget"
+CURL="/usr/bin/curl"
+LYNX="/usr/bin/lynx"
+
+NEWFILE="$FILE.new"
+OLDFILE="$FILE.old"
+
+if [ "$1" = "-q" ]
+then
+    quiet="yes"
 else
-	DECOMP="cat"
+    quiet="no"
 fi
 
-if which curl >/dev/null 2>&1 ; then
-	DL="curl -o $DEST.new $SRC"
-    ${quiet} && DL="$DL -s -S"
-elif which wget >/dev/null 2>&1 ; then
-	DL="wget --no-timestamping -O $DEST.new $SRC"
-	${quiet} && DL="$DL -q"
-elif which lynx >/dev/null 2>&1 ; then
-	DL="eval lynx -source $SRC >$DEST.new"
+if ! $TOUCH $NEWFILE > /dev/null 2>&1
+then
+    $ECHO >&2 "update-pciids: $NEWFILE is read-only"
+    exit 1
+fi
+
+[ -f $NEWFILE ]     && $RM $NEWFILE
+[ -f $NEWFILE.bz2 ] && $RM $NEWFILE.bz2
+[ -f $NEWFILE.gz ]  && $RM $NEWFILE.gz
+
+if [ -x $BUNZIP2 ]
+then
+    EXT=".bz2"
+    UNZIP=$BUNZIP2
+elif [ -x $GUNZIP ]
+then
+    EXT=".gz"
+    UNZIP=$GUNZIP
 else
-	echo >&2 "update-pciids: cannot find curl, wget or lynx"
-	exit 1
+    $ECHO >&2 "update-pciids: cannot find bunzip2 or gunzip"
+    exit 1
 fi
 
-if ! $DL ; then
-	echo >&2 "update-pciids: download failed"
-	rm -f $DEST.new
-	exit 1
+if [ -x $WGET ]
+then
+    $WGET -nv -O $NEWFILE$EXT $URL$EXT > /dev/null 2>&1
+elif [ -x $CURL ]
+then
+    $CURL -o $NEWFILE$EXT $URL$EXT > /dev/null 2>&1
+elif [ -x $LYNX ]
+then
+    $LYNX -source $URL$EXT > $NEWFILE$EXT
+else
+    $ECHO >&2 "update-pciids: cannot find wget, curl or lynx"
+    exit 1
 fi
 
-if ! $DECOMP <$DEST.new >$DEST.neww ; then
-	echo >&2 "update-pciids: decompression failed, probably truncated file"
-	exit 1
+$UNZIP < $NEWFILE$EXT > $NEWFILE
+$RM $NEWFILE$EXT
+
+if ! $GREP > /dev/null "^C " $NEWFILE
+then
+    $ECHO >&2 "update-pciids: missing class info, probably truncated file"
+    exit 1
 fi
 
-if ! $GREP >/dev/null "^C " $DEST.neww ; then
-	echo >&2 "update-pciids: missing class info, probably truncated file"
-	exit 1
+date=$( $GREP -E "^#[[:space:]]Date:[[:space:]]*" $NEWFILE 2> /dev/null | $SED "s/^#[[:space:]]Date:[[:space:]]*//" )
+
+if [ -z "$date" ]
+then
+    $ECHO >&2 "update-pciids: missing snapshot date, probably truncated file"
+    exit 1
+fi 
+
+if [ -f $FILE ]
+then
+    $CHOWN --reference="$FILE" "$NEWFILE"
+    $CHMOD --reference="$FILE" "$NEWFILE"
+    [ -f $OLDFILE ] && $RM $OLDFILE
+    $MV $FILE $OLDFILE
 fi
 
-if [ -f $DEST ] ; then
-	mv $DEST $DEST.old
-	# --reference is supported only by chmod from GNU file, so let's ignore any errors
-	chmod -f --reference=$DEST.old $DEST.neww 2>/dev/null || true
+$MV $NEWFILE $FILE
+$TOUCH -d "$date" $FILE
+
+if [ -f $FILE.gz ]
+then
+    [ -f $OLDFILE.gz ] && $RM $OLDFILE.gz
+    $MV $FILE.gz $OLDFILE.gz
 fi
-mv $DEST.neww $DEST
-rm $DEST.new
 
-# Older versions did not compress the ids file, so let's make sure we
-# clean that up.
-if [ ${DEST%.gz} != ${DEST} ] ; then
-	rm -f ${DEST%.gz} ${DEST%.gz}.old
+if [ $quiet = "no" ]
+then
+    $ECHO "Downloaded daily snapshot dated $date"
 fi
 
-${quiet} || echo "Done."
+exit 0