5 kx #!/bin/sh
5 kx
5 kx # see also update-pciids.sh (fancier)
5 kx
5 kx [ "$1" = "-q" ] && quiet="true" || quiet="false"
5 kx
5 kx set -e
5 kx SRC="http://www.linux-usb.org/usb.ids"
5 kx DEST=@usbids@
5 kx
5 kx # if usb.ids is read-only (because the filesystem is read-only),
5 kx # then just skip this whole process.
5 kx if ! touch ${DEST} >&2 >/dev/null ; then
5 kx ${quiet} || echo "${DEST} is read-only, exiting."
5 kx exit 0
5 kx fi
5 kx
5 kx if which wget >/dev/null 2>&1 ; then
5 kx DL="wget -O $DEST.new $SRC"
5 kx ${quiet} && DL="$DL -q"
5 kx elif which lynx >/dev/null 2>&1 ; then
5 kx DL="eval lynx -source $SRC >$DEST.new"
5 kx else
5 kx echo >&2 "update-usbids: cannot find wget nor lynx"
5 kx exit 1
5 kx fi
5 kx
5 kx if ! $DL ; then
5 kx echo >&2 "update-usbids: download failed"
5 kx rm -f $DEST.new
5 kx exit 1
5 kx fi
5 kx
5 kx if ! grep >/dev/null "^C " $DEST.new ; then
5 kx echo >&2 "update-usbids: missing class info, probably truncated file"
5 kx exit 1
5 kx fi
5 kx
5 kx if [ -f $DEST ] ; then
5 kx mv $DEST $DEST.old
5 kx # --reference is supported only by chmod from GNU file, so let's ignore any errors
5 kx chmod -f --reference=$DEST.old $DEST.new 2>/dev/null || true
5 kx fi
5 kx mv $DEST.new $DEST
5 kx
5 kx ${quiet} || echo "Done."