]> git.ipfire.org Git - thirdparty/pciutils.git/blame - update-pciids.sh
update-pciids: Re-compress pci.ids if needed
[thirdparty/pciutils.git] / update-pciids.sh
CommitLineData
1b95f396
MM
1#!/bin/sh
2
3set -e
bae18059 4
e2d84e91 5SRC="https://pci-ids.ucw.cz/v2.2/pci.ids"
1b95f396 6DEST=pci.ids
cc062b4a
MM
7PCI_COMPRESSED_IDS=
8GREP=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.
14if ! touch ${DEST} >/dev/null 2>&1 ; then
15 ${quiet} || echo "${DEST} is read-only, exiting." 1>&2
16 exit 1
17fi
18
b6e558fb 19if command -v xz >/dev/null 2>&1 ; then
327b6e8a
MM
20 DECOMP="xz -d"
21 SRC="$SRC.xz"
85f05a7c 22elif command -v bzip2 >/dev/null 2>&1 ; then
1b95f396
MM
23 DECOMP="bzip2 -d"
24 SRC="$SRC.bz2"
85f05a7c 25elif command -v gzip >/dev/null 2>&1 ; then
1b95f396
MM
26 DECOMP="gzip -d"
27 SRC="$SRC.gz"
28else
29 DECOMP="cat"
30fi
31
85f05a7c 32if command -v curl >/dev/null 2>&1 ; then
1bbdea17 33 DL="curl -o $DEST.new $SRC"
bae18059 34 ${quiet} && DL="$DL -s -S"
85f05a7c 35elif 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 38elif command -v lynx >/dev/null 2>&1 ; then
1b95f396
MM
39 DL="eval lynx -source $SRC >$DEST.new"
40else
1bbdea17 41 echo >&2 "update-pciids: cannot find curl, wget or lynx"
1b95f396
MM
42 exit 1
43fi
44
45if ! $DL ; then
46 echo >&2 "update-pciids: download failed"
47 rm -f $DEST.new
48 exit 1
49fi
50
b6e558fb 51if ! $DECOMP <$DEST.new >$DEST.new.plain ; then
1b95f396
MM
52 echo >&2 "update-pciids: decompression failed, probably truncated file"
53 exit 1
54fi
55
b6e558fb 56if ! $GREP >/dev/null "^C " $DEST.new.plain ; then
1b95f396
MM
57 echo >&2 "update-pciids: missing class info, probably truncated file"
58 exit 1
59fi
60
61if [ -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
65fi
66
67if [ "$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
74else
75 mv $DEST.new.plain $DEST
76 rm -f $DEST.new
1b95f396 77fi
1b95f396 78
d26b5378
MM
79# Older versions did not compress the ids file, so let's make sure we
80# clean that up.
81if [ ${DEST%.gz} != ${DEST} ] ; then
82 rm -f ${DEST%.gz} ${DEST%.gz}.old
83fi
84
85${quiet} || echo "Done."