]> mj.ucw.cz Git - pciutils.git/blob - update-pciids.sh
Squashed compiler warnings about code with no effect
[pciutils.git] / update-pciids.sh
1 #!/bin/sh
2
3 set -e
4 SRC="http://pciids.sourceforge.net/v2.2/pci.ids"
5 DEST=pci.ids
6 PCI_COMPRESSED_IDS=
7 GREP=grep
8
9 if [ -n "$PCI_COMPRESSED_IDS" ] ; then
10         DECOMP="cat"
11         SRC="$SRC.gz"
12         GREP=zgrep
13 elif which bzip2 >/dev/null ; then
14         DECOMP="bzip2 -d"
15         SRC="$SRC.bz2"
16 elif which gzip >/dev/null ; then
17         DECOMP="gzip -d"
18         SRC="$SRC.gz"
19 else
20         DECOMP="cat"
21 fi
22
23 if which curl >/dev/null ; then
24         DL="curl -o $DEST.new $SRC"
25 elif which wget >/dev/null ; then
26         DL="wget -O $DEST.new $SRC"
27 elif which lynx >/dev/null ; then
28         DL="eval lynx -source $SRC >$DEST.new"
29 else
30         echo >&2 "update-pciids: cannot find curl, wget or lynx"
31         exit 1
32 fi
33
34 if ! $DL ; then
35         echo >&2 "update-pciids: download failed"
36         rm -f $DEST.new
37         exit 1
38 fi
39
40 if ! $DECOMP <$DEST.new >$DEST.neww ; then
41         echo >&2 "update-pciids: decompression failed, probably truncated file"
42         exit 1
43 fi
44
45 if ! $GREP >/dev/null "^C " $DEST.neww ; then
46         echo >&2 "update-pciids: missing class info, probably truncated file"
47         exit 1
48 fi
49
50 if [ -f $DEST ] ; then
51         mv $DEST $DEST.old
52         # --reference is supported only by chmod from GNU file, so let's ignore any errors
53         chmod -f --reference=$DEST.old $DEST.neww 2>/dev/null || true
54 fi
55 mv $DEST.neww $DEST
56 rm $DEST.new
57
58 echo "Done."