Annotation of embedaddon/pciutils/update-pciids.sh, revision 1.1.1.1
1.1 misho 1: #!/bin/sh
2:
3: [ "$1" = "-q" ] && quiet=true || quiet=false
4:
5: set -e
6: SRC="http://pci-ids.ucw.cz/v2.2/pci.ids"
7: DEST=pci.ids
8: PCI_COMPRESSED_IDS=
9: GREP=grep
10:
11: # if pci.ids is read-only (because the filesystem is read-only),
12: # then just skip this whole process.
13: if ! touch ${DEST} >/dev/null 2>&1 ; then
14: ${quiet} || echo "${DEST} is read-only, exiting." 1>&2
15: exit 1
16: fi
17:
18: if [ "$PCI_COMPRESSED_IDS" -eq 1 ] ; then
19: DECOMP="cat"
20: SRC="$SRC.gz"
21: GREP=zgrep
22: elif which bzip2 >/dev/null 2>&1 ; then
23: DECOMP="bzip2 -d"
24: SRC="$SRC.bz2"
25: elif which gzip >/dev/null 2>&1 ; then
26: DECOMP="gzip -d"
27: SRC="$SRC.gz"
28: else
29: DECOMP="cat"
30: fi
31:
32: if which curl >/dev/null 2>&1 ; then
33: DL="curl -o $DEST.new $SRC"
34: ${quiet} && DL="$DL -s -S"
35: elif which wget >/dev/null 2>&1 ; then
36: DL="wget --no-timestamping -O $DEST.new $SRC"
37: ${quiet} && DL="$DL -q"
38: elif which lynx >/dev/null 2>&1 ; then
39: DL="eval lynx -source $SRC >$DEST.new"
40: else
41: echo >&2 "update-pciids: cannot find curl, wget or lynx"
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:
51: if ! $DECOMP <$DEST.new >$DEST.neww ; then
52: echo >&2 "update-pciids: decompression failed, probably truncated file"
53: exit 1
54: fi
55:
56: if ! $GREP >/dev/null "^C " $DEST.neww ; then
57: echo >&2 "update-pciids: missing class info, probably truncated file"
58: exit 1
59: fi
60:
61: if [ -f $DEST ] ; then
62: mv $DEST $DEST.old
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
65: fi
66: mv $DEST.neww $DEST
67: rm $DEST.new
68:
69: # Older versions did not compress the ids file, so let's make sure we
70: # clean that up.
71: if [ ${DEST%.gz} != ${DEST} ] ; then
72: rm -f ${DEST%.gz} ${DEST%.gz}.old
73: fi
74:
75: ${quiet} || echo "Done."
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>