moused - Ease usb mouse attach/detach
[dragonfly.git] / etc / rc.d / moused
1 #!/bin/sh
2 #
3 # $FreeBSD: head/etc/rc.d/moused 240336 2012-09-11 05:04:59Z obrien $
4 #
5
6 # PROVIDE: moused
7 # REQUIRE: DAEMON
8
9 . /etc/rc.subr
10
11 name=moused
12 rcvar=`set_rcvar`
13 command="/usr/sbin/${name}"
14 start_cmd="moused_start"
15 stop_cmd="moused_stop"
16 pidprefix="/var/run/moused"
17 pidfile="${pidprefix}.pid"
18 pidarg=
19 load_rc_config $name
20
21 # Set the pid file and variable name. The second argument, if it exists, is
22 # expected to be the mouse device.
23 #
24 if [ -n "$2" ]; then
25         eval moused_$2_enable=\${moused_$2_enable-${moused_nondefault_enable}}
26         rcvar="moused_${2}_enable"
27         pidfile="${pidprefix}.$2.pid"
28         pidarg="-I $pidfile"
29 fi
30
31 moused_start()
32 {
33         # Set the mouse device and get any related variables. If
34         # a moused device has been specified on the commandline, then
35         # rc.conf(5) variables defined for that device take precedence
36         # over the generic moused_* variables. The only exception is
37         # the moused_port variable, which if not defined sets it to the
38         # passed in device name.
39         #
40         ms=$1
41         if [ -n "$ms" ]; then
42                 eval myflags=\${moused_${ms}_flags-$moused_flags}
43                 eval myport=\${moused_${ms}_port-/dev/$ms}
44                 eval mytype=\${moused_${ms}_type-$moused_type}
45         else
46                 ms="default"
47                 myflags="$moused_flags"
48                 myport="$moused_port"
49                 mytype="$moused_type"
50         fi
51
52         check_startmsgs && echo -n "Starting ${ms} moused"
53         /usr/sbin/moused ${myflags} -p ${myport} -t ${mytype} ${pidarg}
54         check_startmsgs && echo '.'
55
56         mousechar_arg=
57         case ${mousechar_start} in
58         [Nn][Oo] | '')
59                 ;;
60         *)
61                 mousechar_arg="-M ${mousechar_start}"
62                 ;;
63         esac
64
65         for ttyv in /dev/ttyv* ; do
66                 vidcontrol < ${ttyv} ${mousechar_arg} -m on
67         done
68 }
69
70 run_rc_command $*