update-pciids 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/sh
  2. [ "$1" = "-q" ] && quiet=true || quiet=false
  3. set -e
  4. SRC="http://pci-ids.ucw.cz/v2.2/pci.ids"
  5. DEST=/usr/share/pci.ids.gz
  6. PCI_COMPRESSED_IDS=1
  7. GREP=grep
  8. # if pci.ids is read-only (because the filesystem is read-only),
  9. # then just skip this whole process.
  10. if ! touch ${DEST} >/dev/null 2>&1 ; then
  11. ${quiet} || echo "${DEST} is read-only, exiting." 1>&2
  12. exit 1
  13. fi
  14. if [ "$PCI_COMPRESSED_IDS" = 1 ] ; then
  15. DECOMP="cat"
  16. SRC="$SRC.gz"
  17. GREP=zgrep
  18. elif which bzip2 >/dev/null 2>&1 ; then
  19. DECOMP="bzip2 -d"
  20. SRC="$SRC.bz2"
  21. elif which gzip >/dev/null 2>&1 ; then
  22. DECOMP="gzip -d"
  23. SRC="$SRC.gz"
  24. else
  25. DECOMP="cat"
  26. fi
  27. if which curl >/dev/null 2>&1 ; then
  28. DL="curl -o $DEST.new $SRC"
  29. ${quiet} && DL="$DL -s -S"
  30. elif which wget >/dev/null 2>&1 ; then
  31. DL="wget --no-timestamping -O $DEST.new $SRC"
  32. ${quiet} && DL="$DL -q"
  33. elif which lynx >/dev/null 2>&1 ; then
  34. DL="eval lynx -source $SRC >$DEST.new"
  35. else
  36. echo >&2 "update-pciids: cannot find curl, wget or lynx"
  37. exit 1
  38. fi
  39. if ! $DL ; then
  40. echo >&2 "update-pciids: download failed"
  41. rm -f $DEST.new
  42. exit 1
  43. fi
  44. if ! $DECOMP <$DEST.new >$DEST.neww ; then
  45. echo >&2 "update-pciids: decompression failed, probably truncated file"
  46. exit 1
  47. fi
  48. if ! $GREP >/dev/null "^C " $DEST.neww ; then
  49. echo >&2 "update-pciids: missing class info, probably truncated file"
  50. exit 1
  51. fi
  52. if [ -f $DEST ] ; then
  53. mv $DEST $DEST.old
  54. # --reference is supported only by chmod from GNU file, so let's ignore any errors
  55. chmod -f --reference=$DEST.old $DEST.neww 2>/dev/null || true
  56. fi
  57. mv $DEST.neww $DEST
  58. rm $DEST.new
  59. # Older versions did not compress the ids file, so let's make sure we
  60. # clean that up.
  61. if [ ${DEST%.gz} != ${DEST} ] ; then
  62. rm -f ${DEST%.gz} ${DEST%.gz}.old
  63. fi
  64. ${quiet} || echo "Done."