]>
Commit | Line | Data |
---|---|---|
1b95f396 MM |
1 | #!/bin/sh |
2 | ||
d26b5378 MM |
3 | [ "$1" = "-q" ] && quiet=true || quiet=false |
4 | ||
1b95f396 | 5 | set -e |
043ebdee | 6 | SRC="http://pciids.sourceforge.net/v2.2/pci.ids" |
1b95f396 | 7 | DEST=pci.ids |
cc062b4a MM |
8 | PCI_COMPRESSED_IDS= |
9 | GREP=grep | |
1b95f396 | 10 | |
d26b5378 MM |
11 | # if pci.ids is read-only (because the filesystem is read-only), |
12 | # then just skip this whole process. | |
13 | if ! touch ${DEST} >/dev/null 2>&1 ; then | |
14 | ${quiet} || echo "${DEST} is read-only, exiting." 1>&2 | |
15 | exit 1 | |
16 | fi | |
17 | ||
cc062b4a MM |
18 | if [ -n "$PCI_COMPRESSED_IDS" ] ; then |
19 | DECOMP="cat" | |
20 | SRC="$SRC.gz" | |
21 | GREP=zgrep | |
d26b5378 | 22 | elif which bzip2 >/dev/null 2>&1 ; then |
1b95f396 MM |
23 | DECOMP="bzip2 -d" |
24 | SRC="$SRC.bz2" | |
d26b5378 | 25 | elif which gzip >/dev/null 2>&1 ; then |
1b95f396 MM |
26 | DECOMP="gzip -d" |
27 | SRC="$SRC.gz" | |
28 | else | |
29 | DECOMP="cat" | |
30 | fi | |
31 | ||
d26b5378 | 32 | if which curl >/dev/null 2>&1 ; then |
1bbdea17 | 33 | DL="curl -o $DEST.new $SRC" |
d26b5378 MM |
34 | ${quiet} && DL="$DL -s -S" |
35 | elif which wget >/dev/null 2>&1 ; then | |
c7045bf2 | 36 | DL="wget --no-timestamping -O $DEST.new $SRC" |
d26b5378 MM |
37 | ${quiet} && DL="$DL -q" |
38 | elif which lynx >/dev/null 2>&1 ; then | |
1b95f396 MM |
39 | DL="eval lynx -source $SRC >$DEST.new" |
40 | else | |
1bbdea17 | 41 | echo >&2 "update-pciids: cannot find curl, wget or lynx" |
1b95f396 MM |
42 | exit 1 |
43 | fi | |
44 | ||
45 | if ! $DL ; then | |
46 | echo >&2 "update-pciids: download failed" | |
47 | rm -f $DEST.new | |
48 | exit 1 | |
49 | fi | |
50 | ||
51 | if ! $DECOMP <$DEST.new >$DEST.neww ; then | |
52 | echo >&2 "update-pciids: decompression failed, probably truncated file" | |
53 | exit 1 | |
54 | fi | |
55 | ||
cc062b4a | 56 | if ! $GREP >/dev/null "^C " $DEST.neww ; then |
1b95f396 MM |
57 | echo >&2 "update-pciids: missing class info, probably truncated file" |
58 | exit 1 | |
59 | fi | |
60 | ||
61 | if [ -f $DEST ] ; then | |
62 | mv $DEST $DEST.old | |
80b3121a MM |
63 | # --reference is supported only by chmod from GNU file, so let's ignore any errors |
64 | chmod -f --reference=$DEST.old $DEST.neww 2>/dev/null || true | |
1b95f396 MM |
65 | fi |
66 | mv $DEST.neww $DEST | |
67 | rm $DEST.new | |
68 | ||
d26b5378 MM |
69 | # Older versions did not compress the ids file, so let's make sure we |
70 | # clean that up. | |
71 | if [ ${DEST%.gz} != ${DEST} ] ; then | |
72 | rm -f ${DEST%.gz} ${DEST%.gz}.old | |
73 | fi | |
74 | ||
75 | ${quiet} || echo "Done." |