]>
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 | ||
b6e558fb | 19 | if command -v xz >/dev/null 2>&1 ; then |
327b6e8a MM |
20 | DECOMP="xz -d" |
21 | SRC="$SRC.xz" | |
85f05a7c | 22 | elif command -v bzip2 >/dev/null 2>&1 ; then |
1b95f396 MM |
23 | DECOMP="bzip2 -d" |
24 | SRC="$SRC.bz2" | |
85f05a7c | 25 | elif command -v gzip >/dev/null 2>&1 ; then |
1b95f396 MM |
26 | DECOMP="gzip -d" |
27 | SRC="$SRC.gz" | |
28 | else | |
29 | DECOMP="cat" | |
30 | fi | |
31 | ||
85f05a7c | 32 | if command -v curl >/dev/null 2>&1 ; then |
1bbdea17 | 33 | DL="curl -o $DEST.new $SRC" |
bae18059 | 34 | ${quiet} && DL="$DL -s -S" |
85f05a7c | 35 | elif command -v wget >/dev/null 2>&1 ; then |
c7045bf2 | 36 | DL="wget --no-timestamping -O $DEST.new $SRC" |
d26b5378 | 37 | ${quiet} && DL="$DL -q" |
85f05a7c | 38 | elif command -v 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 | ||
b6e558fb | 51 | if ! $DECOMP <$DEST.new >$DEST.new.plain ; then |
1b95f396 MM |
52 | echo >&2 "update-pciids: decompression failed, probably truncated file" |
53 | exit 1 | |
54 | fi | |
55 | ||
b6e558fb | 56 | if ! $GREP >/dev/null "^C " $DEST.new.plain ; 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 | |
b6a0091e | 62 | ln -f $DEST $DEST.old |
80b3121a | 63 | # --reference is supported only by chmod from GNU file, so let's ignore any errors |
b6e558fb MM |
64 | chmod -f --reference=$DEST.old $DEST.new $DEST.new.plain 2>/dev/null || true |
65 | fi | |
66 | ||
67 | if [ "$PCI_COMPRESSED_IDS" = 1 ] ; then | |
68 | if [ "${SRC%.gz}" != .gz ] ; then | |
69 | # Recompress to gzip | |
70 | gzip <$DEST.new.plain >$DEST.new | |
71 | fi | |
72 | mv $DEST.new $DEST | |
73 | rm -f $DEST.new.plain | |
74 | else | |
75 | mv $DEST.new.plain $DEST | |
76 | rm -f $DEST.new | |
1b95f396 | 77 | fi |
1b95f396 | 78 | |
d26b5378 MM |
79 | # Older versions did not compress the ids file, so let's make sure we |
80 | # clean that up. | |
81 | if [ ${DEST%.gz} != ${DEST} ] ; then | |
82 | rm -f ${DEST%.gz} ${DEST%.gz}.old | |
83 | fi | |
84 | ||
85 | ${quiet} || echo "Done." |