e5e37b2dcd07ba71df787655db3c54391f2da182
[packages/bluez-utils.git] / bluez-utils.init
1 #!/bin/sh
2 #
3 # bluetooth     Bluetooth subsystem starting and stopping
4 #
5 # chkconfig:    345 25 90
6 #
7 # description:  Bluetooth subsystem
8 #
9 # $Id$
10
11
12 # Source function library
13 . /etc/rc.d/init.d/functions
14
15 UART_CONF="/etc/bluetooth/uart"
16 [ -f /etc/sysconfig/bluetooth ] && . /etc/sysconfig/bluetooth
17
18 if [ "$UART_CONF" != "no" -a ! -f "$UART_CONF" ]; then
19         UART_CONF="no"
20 fi
21
22 start() {
23         # Check if the service is already running?
24         if [ ! -f /var/lock/subsys/bluetooth ]; then
25                 msg_starting bluetooth; started
26                 if is_yes "${HID2HCI_ENABLE}" && [ -x /usr/sbin/hid2hci ]; then
27                         msg_starting hid2hci
28                         daemon /usr/sbin/hid2hci -0 -q    #be quiet
29                         RETVAL=$?
30                         /bin/sleep 1 # delay for hid's to be detected by hotplug
31                 fi
32                 
33                 if is_yes "${HCID_ENABLE}" && [ -x /usr/sbin/hcid ]; then
34                         msg_starting hcid
35                         daemon /usr/sbin/hcid -f /etc/bluetooth/hcid.conf
36                         RETVAL=$?
37                 fi
38         
39                 if is_yes "${SDPD_ENABLE}" && [ -x /usr/sbin/sdpd ]; then
40                         msg_starting sdpd
41                         daemon /usr/sbin/sdpd
42                         RETVAL=$?
43                 fi
44                 
45                 if is_yes "${HIDD_ENABLE}" && [ -x /usr/bin/hidd ]; then
46                         msg_starting hidd
47                         daemon /usr/bin/hidd ${HIDD_OPTIONS} --server
48                         RETVAL=$?
49                 fi
50
51                 if is_yes "${RFCOMM_ENABLE}" && [ -x /usr/bin/rfcomm ]; then
52                         msg_starting rfcomm
53                         daemon /usr/bin/rfcomm -f /etc/bluetooth/rfcomm.conf bind all
54                         RETVAL=$?
55                 fi
56         
57                 if is_yes "${DUND_ENABLE}" && [ -x /usr/bin/dund ]; then
58                         msg_starting dund
59                         daemon /usr/bin/dund ${DUND_OPTIONS}
60                         RETVAL=$?
61                 fi
62         
63                 if is_yes "${PAND_ENABLE}" && [ -x /usr/bin/pand ]; then
64                         msg_starting pand
65                         daemon /usr/bin/pand ${PAND_OPTIONS}
66                         RETVAL=$?
67                 fi
68
69                 if [ -f /usr/sbin/hciattach -a "$UART_CONF" != "no" ]; then
70                         grep -v '^#' $UART_CONF | while read i; do
71                                 /usr/sbin/hciattach $i
72                         done
73                 fi
74                 [ $RETVAL -eq 0 ] && touch /var/lock/subsys/bluetooth
75         else
76                 msg_already_running bluetooth
77         fi
78 }
79
80 stop() {
81         if [ -f /var/lock/subsys/bluetooth ]; then
82                 if is_yes "${PAND_ENABLE}" && [ -x /usr/bin/pand ]; then
83                         msg_stopping pand
84                         killproc /usr/bin/pand
85                 fi
86
87                 if is_yes "${DUND_ENABLE}" && [ -x /usr/bin/dund ]; then
88                         msg_stopping dund
89                         killproc /usr/bin/dund
90                 fi
91
92                 if is_yes "${RFCOMM_ENABLE}" && [ -x /usr/bin/rfcomm ]; then
93                         msg_stopping rfcomm
94                         daemon /usr/bin/rfcomm release all
95                 fi
96
97                 if is_yes "${HIDD_ENABLE}" && [ -x  /usr/bin/hidd ]; then
98                         msg_stopping hidd
99                         killproc /usr/bin/hidd
100                 fi
101         
102                 if is_yes "${SDPD_ENABLE}" && [ -x /usr/sbin/sdpd ]; then
103                         msg_stopping sdpd
104                         killproc /usr/sbin/sdpd
105                 fi
106         
107                 if is_yes "${HCID_ENABLE}" && [ -x /usr/sbin/hcid ]; then
108                         msg_stopping hcid
109                         killproc /usr/sbin/hcid
110                 fi
111
112                 if [ "$UART_CONF" != "no" ]; then
113                         killproc hciattach >/dev/null 2>&1
114                 fi
115                 rm -f /var/lock/subsys/bluetooth
116         else
117                 msg_not_running bluetooth
118         fi
119 }
120
121 RETVAL=0
122 # See how we were called.
123 case "$1" in
124   start)
125         start
126         ;;
127   stop)
128         stop
129         ;;
130   restart)
131         stop
132         start
133         ;;
134   reload|force-reload)
135         if [ -f /var/lock/subsys/bluetooth ]; then
136                 msg_reloading hcid
137                 killproc hcid -HUP
138                 RETVAL=$?
139         else
140                 msg_not_running bluetooth
141                 exit 7
142         fi
143         ;;
144   status)
145         is_yes "${HID2HCI_ENABLE}" && status hid2hci
146         is_yes "${HCID_ENABLE}" && status hcid
147         is_yes "${SDPD_ENABLE}" && status sdpd
148         is_yes "${HIDD_ENABLE}" && status hidd
149         is_yes "${DUND_ENABLE}" && status dund
150         if [ -f /var/lock/subsys/bluetooth ]; then
151                 exit 0
152         else
153                 exit 1
154         fi              
155         ;;
156   *)
157         msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
158         exit 3
159 esac
160
161 exit $RETVAL
This page took 0.106682 seconds and 2 git commands to generate.