]> mj.ucw.cz Git - pciutils.git/blob - update-pciids.sh
Memleak
[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
7 if which bzip2 >/dev/null ; then
8         DECOMP="bzip2 -d"
9         SRC="$SRC.bz2"
10 elif which gzip >/dev/null ; then
11         DECOMP="gzip -d"
12         SRC="$SRC.gz"
13 else
14         DECOMP="cat"
15 fi
16
17 if which wget >/dev/null ; then
18         DL="wget -O $DEST.new $SRC"
19 elif which lynx >/dev/null ; then
20         DL="eval lynx -source $SRC >$DEST.new"
21 else
22         echo >&2 "update-pciids: cannot find wget nor lynx"
23         exit 1
24 fi
25
26 if ! $DL ; then
27         echo >&2 "update-pciids: download failed"
28         rm -f $DEST.new
29         exit 1
30 fi
31
32 if ! $DECOMP <$DEST.new >$DEST.neww ; then
33         echo >&2 "update-pciids: decompression failed, probably truncated file"
34         exit 1
35 fi
36
37 if ! grep >/dev/null "^C " $DEST.neww ; then
38         echo >&2 "update-pciids: missing class info, probably truncated file"
39         exit 1
40 fi
41
42 if [ -f $DEST ] ; then
43         mv $DEST $DEST.old
44         # --reference is supported only by chmod from GNU file, so let's ignore any errors
45         chmod -f --reference=$DEST.old $DEST.neww 2>/dev/null || true
46 fi
47 mv $DEST.neww $DEST
48 rm $DEST.new
49
50 echo "Done."