~ubuntu-branches/ubuntu/saucy/joystick/saucy

« back to all changes in this revision

Viewing changes to utils/jscal-restore.in

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Kitt
  • Date: 2011-04-04 16:56:39 UTC
  • mto: (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: james.westby@ubuntu.com-20110404165639-k7yh9rf1yd1dhobd
Tags: upstream-1.4~rc1
ImportĀ upstreamĀ versionĀ 1.4~rc1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
if [ -z "$1" ]; then
 
4
    echo "Usage: $0 {device}"
 
5
    echo "Restores the device's calibration."
 
6
    exit 1
 
7
fi
 
8
 
 
9
if [ ! -x /sbin/udevadm ]; then
 
10
    echo Restoring joystick configuration requires udev! >&2
 
11
    exit 1
 
12
fi
 
13
 
 
14
STORE=/var/lib/joystick/joystick.state
 
15
 
 
16
if [ ! -f $STORE ]; then
 
17
    echo No saved joystick configuration\(s\) to restore! >&2
 
18
    exit 1
 
19
fi
 
20
 
 
21
DEVICE=""
 
22
NAME=""
 
23
SERIAL=""
 
24
VENDOR=""
 
25
PRODUCT=""
 
26
 
 
27
# Backup original $IFS (Internal Field Separator) variable
 
28
OIFS=$IFS
 
29
# Set $IFS to newline only as output from @@PREFIX@@/share/joystick/ident might contain spaces
 
30
# in the NAME value
 
31
IFS=$'\x0A'
 
32
 
 
33
for ATTRIBUTE in $( /sbin/udevadm info -a -n $1 | @@PREFIX@@/share/joystick/ident ); do
 
34
    ID=$( echo "$ATTRIBUTE" | cut -f 1 -d = )
 
35
    VALUE=$( echo "$ATTRIBUTE" | cut -f 2 -d \" )
 
36
    case $ID in
 
37
        "DEVICE" ) DEVICE="$VALUE" ;;
 
38
        "NAME" ) NAME="$VALUE" ;;
 
39
        "SERIAL" ) SERIAL="$VALUE" ;;
 
40
        "VENDOR" ) VENDOR="$VALUE" ;;
 
41
        "PRODUCT" ) PRODUCT="$VALUE" ;;
 
42
    esac
 
43
done
 
44
 
 
45
# Restore original $IFS
 
46
IFS=$OIFS
 
47
 
 
48
# Retrieve the applicable commands
 
49
if [ -z "$NAME" ] && [ -z "$VENDOR" ]; then
 
50
    # Use the device name only
 
51
    cat $STORE | @@PREFIX@@/share/joystick/extract kernel="$DEVICE" | while read COMMAND; do
 
52
        $COMMAND $1
 
53
    done
 
54
else
 
55
    cat $STORE | @@PREFIX@@/share/joystick/extract name="$NAME" serial="$SERIAL" vendor="$VENDOR" product="$PRODUCT" | while read COMMAND; do
 
56
        $COMMAND $1
 
57
    done
 
58
fi
 
59