]> git.ipfire.org Git - thirdparty/pciutils.git/blame - update-pciids.sh
Sylixos port
[thirdparty/pciutils.git] / update-pciids.sh
CommitLineData
1b95f396
MM
1#!/bin/sh
2
d26b5378
MM
3[ "$1" = "-q" ] && quiet=true || quiet=false
4
1b95f396 5set -e
97add73f 6SRC="http://pci-ids.ucw.cz/v2.2/pci.ids"
1b95f396 7DEST=pci.ids
cc062b4a
MM
8PCI_COMPRESSED_IDS=
9GREP=grep
1b95f396 10
d26b5378
MM
11# if pci.ids is read-only (because the filesystem is read-only),
12# then just skip this whole process.
13if ! touch ${DEST} >/dev/null 2>&1 ; then
14 ${quiet} || echo "${DEST} is read-only, exiting." 1>&2
15 exit 1
16fi
17
43391150 18if [ "$PCI_COMPRESSED_IDS" = 1 ] ; then
cc062b4a
MM
19 DECOMP="cat"
20 SRC="$SRC.gz"
21 GREP=zgrep
d26b5378 22elif which bzip2 >/dev/null 2>&1 ; then
1b95f396
MM
23 DECOMP="bzip2 -d"
24 SRC="$SRC.bz2"
d26b5378 25elif which gzip >/dev/null 2>&1 ; then
1b95f396
MM
26 DECOMP="gzip -d"
27 SRC="$SRC.gz"
28else
29 DECOMP="cat"
30fi
31
d26b5378 32if which curl >/dev/null 2>&1 ; then
1bbdea17 33 DL="curl -o $DEST.new $SRC"
d26b5378
MM
34 ${quiet} && DL="$DL -s -S"
35elif which wget >/dev/null 2>&1 ; then
c7045bf2 36 DL="wget --no-timestamping -O $DEST.new $SRC"
d26b5378
MM
37 ${quiet} && DL="$DL -q"
38elif which 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
51if ! $DECOMP <$DEST.new >$DEST.neww ; then
52 echo >&2 "update-pciids: decompression failed, probably truncated file"
53 exit 1
54fi
55
cc062b4a 56if ! $GREP >/dev/null "^C " $DEST.neww ; then
1b95f396
MM
57 echo >&2 "update-pciids: missing class info, probably truncated file"
58 exit 1
59fi
60
61if [ -f $DEST ] ; then
62 mv $DEST $DEST.old
80b3121a
MM
63 # --reference is supported only by chmod from GNU file, so let's ignore any errors
64 chmod -f --reference=$DEST.old $DEST.neww 2>/dev/null || true
1b95f396
MM
65fi
66mv $DEST.neww $DEST
67rm $DEST.new
68
d26b5378
MM
69# Older versions did not compress the ids file, so let's make sure we
70# clean that up.
71if [ ${DEST%.gz} != ${DEST} ] ; then
72 rm -f ${DEST%.gz} ${DEST%.gz}.old
73fi
74
75${quiet} || echo "Done."