]> git.ipfire.org Git - thirdparty/pciutils.git/blame - update-pciids.sh
maint/README: git push --tags is done by push-to-public
[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
7ec58f1c
MM
9VERSION=unknown
10USER_AGENT=update-pciids/$VERSION
11QUIET=
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.
17if ! touch ${DEST} >/dev/null 2>&1 ; then
18 ${quiet} || echo "${DEST} is read-only, exiting." 1>&2
19 exit 1
20fi
21
b6e558fb 22if command -v xz >/dev/null 2>&1 ; then
327b6e8a
MM
23 DECOMP="xz -d"
24 SRC="$SRC.xz"
85f05a7c 25elif command -v bzip2 >/dev/null 2>&1 ; then
1b95f396
MM
26 DECOMP="bzip2 -d"
27 SRC="$SRC.bz2"
85f05a7c 28elif command -v gzip >/dev/null 2>&1 ; then
1b95f396
MM
29 DECOMP="gzip -d"
30 SRC="$SRC.gz"
31else
32 DECOMP="cat"
33fi
34
85f05a7c 35if 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 41elif 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 47elif 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 52else
1bbdea17 53 echo >&2 "update-pciids: cannot find curl, wget or lynx"
1b95f396
MM
54 exit 1
55fi
56
7ec58f1c 57if ! dl ; then
1b95f396
MM
58 echo >&2 "update-pciids: download failed"
59 rm -f $DEST.new
60 exit 1
61fi
62
b6e558fb 63if ! $DECOMP <$DEST.new >$DEST.new.plain ; then
1b95f396
MM
64 echo >&2 "update-pciids: decompression failed, probably truncated file"
65 exit 1
66fi
67
b6e558fb 68if ! $GREP >/dev/null "^C " $DEST.new.plain ; then
1b95f396
MM
69 echo >&2 "update-pciids: missing class info, probably truncated file"
70 exit 1
71fi
72
73if [ -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
77fi
78
79if [ "$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
86else
87 mv $DEST.new.plain $DEST
88 rm -f $DEST.new
1b95f396 89fi
1b95f396 90
d26b5378
MM
91# Older versions did not compress the ids file, so let's make sure we
92# clean that up.
93if [ ${DEST%.gz} != ${DEST} ] ; then
94 rm -f ${DEST%.gz} ${DEST%.gz}.old
95fi
96
97${quiet} || echo "Done."