]>
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 | |
7ec58f1c MM |
9 | VERSION=unknown |
10 | USER_AGENT=update-pciids/$VERSION | |
11 | QUIET= | |
1b95f396 | 12 | |
20e206ec GJ |
13 | [ "$1" = "-q" ] && quiet=true || quiet=false |
14 | ||
d26b5378 MM |
15 | # if pci.ids is read-only (because the filesystem is read-only), |
16 | # then just skip this whole process. | |
17 | if ! touch ${DEST} >/dev/null 2>&1 ; then | |
18 | ${quiet} || echo "${DEST} is read-only, exiting." 1>&2 | |
19 | exit 1 | |
20 | fi | |
21 | ||
b6e558fb | 22 | if command -v xz >/dev/null 2>&1 ; then |
327b6e8a MM |
23 | DECOMP="xz -d" |
24 | SRC="$SRC.xz" | |
85f05a7c | 25 | elif command -v bzip2 >/dev/null 2>&1 ; then |
1b95f396 MM |
26 | DECOMP="bzip2 -d" |
27 | SRC="$SRC.bz2" | |
85f05a7c | 28 | elif command -v gzip >/dev/null 2>&1 ; then |
1b95f396 MM |
29 | DECOMP="gzip -d" |
30 | SRC="$SRC.gz" | |
31 | else | |
32 | DECOMP="cat" | |
33 | fi | |
34 | ||
85f05a7c | 35 | if command -v curl >/dev/null 2>&1 ; then |
7ec58f1c MM |
36 | ${quiet} && QUIET="-s -S" |
37 | dl () | |
38 | { | |
39 | curl -o $DEST.new --user-agent "$USER_AGENT curl" $QUIET $SRC | |
40 | } | |
85f05a7c | 41 | elif command -v wget >/dev/null 2>&1 ; then |
7ec58f1c MM |
42 | ${quiet} && QUIET="-q" |
43 | dl () | |
44 | { | |
45 | wget --no-timestamping -O $DEST.new --user-agent "$USER_AGENT wget" $QUIET $SRC | |
46 | } | |
85f05a7c | 47 | elif command -v lynx >/dev/null 2>&1 ; then |
7ec58f1c MM |
48 | dl () |
49 | { | |
50 | lynx -source -useragent="$USER_AGENT lynx" $SRC >$DEST.new | |
51 | } | |
1b95f396 | 52 | else |
1bbdea17 | 53 | echo >&2 "update-pciids: cannot find curl, wget or lynx" |
1b95f396 MM |
54 | exit 1 |
55 | fi | |
56 | ||
7ec58f1c | 57 | if ! dl ; then |
1b95f396 MM |
58 | echo >&2 "update-pciids: download failed" |
59 | rm -f $DEST.new | |
60 | exit 1 | |
61 | fi | |
62 | ||
b6e558fb | 63 | if ! $DECOMP <$DEST.new >$DEST.new.plain ; then |
1b95f396 MM |
64 | echo >&2 "update-pciids: decompression failed, probably truncated file" |
65 | exit 1 | |
66 | fi | |
67 | ||
b6e558fb | 68 | if ! $GREP >/dev/null "^C " $DEST.new.plain ; then |
1b95f396 MM |
69 | echo >&2 "update-pciids: missing class info, probably truncated file" |
70 | exit 1 | |
71 | fi | |
72 | ||
73 | if [ -f $DEST ] ; then | |
b6a0091e | 74 | ln -f $DEST $DEST.old |
80b3121a | 75 | # --reference is supported only by chmod from GNU file, so let's ignore any errors |
b6e558fb MM |
76 | chmod -f --reference=$DEST.old $DEST.new $DEST.new.plain 2>/dev/null || true |
77 | fi | |
78 | ||
79 | if [ "$PCI_COMPRESSED_IDS" = 1 ] ; then | |
80 | if [ "${SRC%.gz}" != .gz ] ; then | |
81 | # Recompress to gzip | |
82 | gzip <$DEST.new.plain >$DEST.new | |
83 | fi | |
84 | mv $DEST.new $DEST | |
85 | rm -f $DEST.new.plain | |
86 | else | |
87 | mv $DEST.new.plain $DEST | |
88 | rm -f $DEST.new | |
1b95f396 | 89 | fi |
1b95f396 | 90 | |
d26b5378 MM |
91 | # Older versions did not compress the ids file, so let's make sure we |
92 | # clean that up. | |
93 | if [ ${DEST%.gz} != ${DEST} ] ; then | |
94 | rm -f ${DEST%.gz} ${DEST%.gz}.old | |
95 | fi | |
96 | ||
97 | ${quiet} || echo "Done." |