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