upload tizen2.0 source
[framework/system/usbutils.git] / update-usbids.sh.in
1 #!/bin/sh
2
3 # see also update-pciids.sh (fancier)
4
5 [ "$1" = "-q" ] && quiet="true" || quiet="false"
6
7 set -e
8 SRC="http://www.linux-usb.org/usb.ids"
9 DEST=@usbids@
10
11 # if usb.ids is read-only (because the filesystem is read-only),
12 # then just skip this whole process.
13 if ! touch ${DEST} >&2 >/dev/null ; then
14         ${quiet} || echo "${DEST} is read-only, exiting."
15         exit 0
16 fi
17
18 if which wget >/dev/null 2>&1 ; then
19         DL="wget -O $DEST.new $SRC"
20         ${quiet} && DL="$DL -q"
21 elif which lynx >/dev/null 2>&1 ; then
22         DL="eval lynx -source $SRC >$DEST.new"
23 else
24         echo >&2 "update-usbids: cannot find wget nor lynx"
25         exit 1
26 fi
27
28 if ! $DL ; then
29         echo >&2 "update-usbids: download failed"
30         rm -f $DEST.new
31         exit 1
32 fi
33
34 if ! grep >/dev/null "^C " $DEST.new ; then
35         echo >&2 "update-usbids: missing class info, probably truncated file"
36         exit 1
37 fi
38
39 if [ -f $DEST ] ; then
40         mv $DEST $DEST.old
41         # --reference is supported only by chmod from GNU file, so let's ignore any errors
42         chmod -f --reference=$DEST.old $DEST.new 2>/dev/null || true
43 fi
44 mv $DEST.new $DEST
45
46 ${quiet} || echo "Done."