]> git.ipfire.org Git - thirdparty/pciutils.git/blob - update-pciids.sh
ls-ecaps: extend decode support for more fields for AER CE and UE status
[thirdparty/pciutils.git] / update-pciids.sh
1 #!/bin/sh
2
3 set -e
4
5 SRC="https://pci-ids.ucw.cz/v2.2/pci.ids"
6 DEST=pci.ids
7 PCI_COMPRESSED_IDS=
8 GREP=grep
9 VERSION=unknown
10 USER_AGENT=update-pciids/$VERSION
11 QUIET=
12
13 [ "$1" = "-q" ] && quiet=true || quiet=false
14
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
22 if command -v xz >/dev/null 2>&1 ; then
23 DECOMP="xz -d"
24 SRC="$SRC.xz"
25 elif command -v bzip2 >/dev/null 2>&1 ; then
26 DECOMP="bzip2 -d"
27 SRC="$SRC.bz2"
28 elif command -v gzip >/dev/null 2>&1 ; then
29 DECOMP="gzip -d"
30 SRC="$SRC.gz"
31 else
32 DECOMP="cat"
33 fi
34
35 if command -v curl >/dev/null 2>&1 ; then
36 ${quiet} && QUIET="-s -S"
37 dl ()
38 {
39 curl -o $DEST.new --user-agent "$USER_AGENT curl" $QUIET $SRC
40 }
41 elif command -v wget >/dev/null 2>&1 ; then
42 ${quiet} && QUIET="-q"
43 dl ()
44 {
45 wget --no-timestamping -O $DEST.new --user-agent "$USER_AGENT wget" $QUIET $SRC
46 }
47 elif command -v lynx >/dev/null 2>&1 ; then
48 dl ()
49 {
50 lynx -source -useragent="$USER_AGENT lynx" $SRC >$DEST.new
51 }
52 else
53 echo >&2 "update-pciids: cannot find curl, wget or lynx"
54 exit 1
55 fi
56
57 if ! dl ; then
58 echo >&2 "update-pciids: download failed"
59 rm -f $DEST.new
60 exit 1
61 fi
62
63 if ! $DECOMP <$DEST.new >$DEST.new.plain ; then
64 echo >&2 "update-pciids: decompression failed, probably truncated file"
65 exit 1
66 fi
67
68 if ! $GREP >/dev/null "^C " $DEST.new.plain ; then
69 echo >&2 "update-pciids: missing class info, probably truncated file"
70 exit 1
71 fi
72
73 if [ -f $DEST ] ; then
74 ln -f $DEST $DEST.old
75 # --reference is supported only by chmod from GNU file, so let's ignore any errors
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
89 fi
90
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."