summaryrefslogtreecommitdiffstats
path: root/contrib/check_joy.sh
blob: cd076db905764d532f1a192cec4746cd5d36dcd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#! /bin/sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision$' | sed -e 's/[^0-9.]//g'`
STATUS=""

. $PROGPATH/utils.sh


print_usage() {
        echo "Usage: $PROGNAME /dev/js<#> <button #>"
}

print_help() {
        print_revision $PROGNAME $REVISION
        echo ""
        print_usage
        echo ""
        echo "This plugin checks a joystick button status using the "
        echo "joyreadbutton utility from the joyd package."
        echo ""
        support
        exit 0
}

if [ $# -ne 2 ]; then
        print_usage
        exit 0
fi

case "$1" in
        --help)
                print_help
                exit 0
                ;;
        -h)
                print_help
                exit 0
                ;;
        --version)
        print_revision $PROGNAME $REVISION
                exit 0
                ;;
        -V)
                print_revision $PROGNAME $REVISION
                exit 0
                ;;
        /dev/js*)
                joyreadbutton $1 $2 1>&1 1>/dev/null
                STATUS=$?
                if [ "$STATUS" -eq 0 ]; then
                        echo OK
                        exit 0
                elif [ "$STATUS" -eq 1 ];then
                        echo CRITICAL
                        exit 2
                else
                        echo UNKNOWN
                        exit -1
                fi
                ;;
        *)
                print_usage
                exit 0
                ;;
esac