add SMACK manifest file
[framework/system/pciutils.git] / update-pciids.sh
1 #!/bin/sh
2
3 # update-pciids.sh is licensed under the GNU General Public License
4 # (GPL) version 2 or above.
5
6 # Copyright (C) 2008  Anibal Monsalve Salazar <anibal@debian.org>
7
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # Please read the "COPYING" file in the archive root, or visit
19 # http://www.gnu.org/licenses/gpl.html, for information about the GPL.
20 #
21 # This scipt is a rewrite of a script with the same name by
22 # Martin Mares.
23
24 set -e
25
26 #URL="http://pci-ids.ucw.cz/pci.ids"
27 URL="http://pciids.sourceforge.net/v2.2/pci.ids"
28 FILE="pci.ids"
29
30 RM="/bin/rm"
31 MV="/bin/mv"
32 SED="/bin/sed"
33 GREP="/bin/grep"
34 GZIP="/bin/gzip"
35 ECHO="/bin/echo"
36 CHMOD="/bin/chmod"
37 GUNZIP="/bin/gunzip"
38 BUNZIP2="/bin/bunzip2"
39 TOUCH="/usr/bin/touch"
40 WGET="/usr/bin/wget"
41 CURL="/usr/bin/curl"
42 LYNX="/usr/bin/lynx"
43
44 NEWFILE="$FILE.new"
45 OLDFILE="$FILE.old"
46
47 if [ "$1" = "-q" ]
48 then
49     quiet="yes"
50 else
51     quiet="no"
52 fi
53
54 if ! $TOUCH $NEWFILE > /dev/null 2>&1
55 then
56     $ECHO >&2 "update-pciids: $NEWFILE is read-only"
57     exit 1
58 fi
59
60 [ -f $NEWFILE ]     && $RM $NEWFILE
61 [ -f $NEWFILE.bz2 ] && $RM $NEWFILE.bz2
62 [ -f $NEWFILE.gz ]  && $RM $NEWFILE.gz
63
64 if [ -x $BUNZIP2 ]
65 then
66     EXT=".bz2"
67     UNZIP=$BUNZIP2
68 elif [ -x $GUNZIP ]
69 then
70     EXT=".gz"
71     UNZIP=$GUNZIP
72 else
73     $ECHO >&2 "update-pciids: cannot find bunzip2 or gunzip"
74     exit 1
75 fi
76
77 if [ -x $WGET ]
78 then
79     $WGET -nv -O $NEWFILE$EXT $URL$EXT > /dev/null 2>&1
80 elif [ -x $CURL ]
81 then
82     $CURL -o $NEWFILE$EXT $URL$EXT > /dev/null 2>&1
83 elif [ -x $LYNX ]
84 then
85     $LYNX -source $URL$EXT > $NEWFILE$EXT
86 else
87     $ECHO >&2 "update-pciids: cannot find wget, curl or lynx"
88     exit 1
89 fi
90
91 $UNZIP < $NEWFILE$EXT > $NEWFILE
92 $RM $NEWFILE$EXT
93
94 if ! $GREP > /dev/null "^C " $NEWFILE
95 then
96     $ECHO >&2 "update-pciids: missing class info, probably truncated file"
97     exit 1
98 fi
99
100 date=$( $GREP -E "^#[[:space:]]Date:[[:space:]]*" $NEWFILE 2> /dev/null | $SED "s/^#[[:space:]]Date:[[:space:]]*//" )
101
102 if [ -z "$date" ]
103 then
104     $ECHO >&2 "update-pciids: missing snapshot date, probably truncated file"
105     exit 1
106 fi 
107
108 if [ -f $FILE ]
109 then
110     [ -f $OLDFILE ] && $RM $OLDFILE
111     $MV $FILE $OLDFILE
112 fi
113
114 $MV $NEWFILE $FILE
115 $TOUCH -d "$date" $FILE
116
117 if [ -f $FILE.gz ]
118 then
119     [ -f $OLDFILE.gz ] && $RM $OLDFILE.gz
120     $MV $FILE.gz $OLDFILE.gz
121 fi
122
123 if [ $quiet = "no" ]
124 then
125     $ECHO "Downloaded daily snapshot dated $date"
126 fi
127
128 exit 0