1#!/bin/sh
2
3DAEMON="bluetoothd"
4PIDFILE="/var/run/$DAEMON.pid"
5
6BLUETOOTHD_ARGS="-n"
7
8# shellcheck source=/dev/null
9[ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
10
11start() {
12	printf 'Starting %s: ' "$DAEMON"
13	# shellcheck disable=SC2086 # we need the word splitting
14	start-stop-daemon -S -q -m -b -p "$PIDFILE" -x "/usr/libexec/bluetooth/$DAEMON" \
15		-- $BLUETOOTHD_ARGS
16	status=$?
17	if [ "$status" -eq 0 ]; then
18		echo "OK"
19	else
20		echo "FAIL"
21	fi
22	return "$status"
23}
24
25stop() {
26	printf 'Stopping %s: ' "$DAEMON"
27	start-stop-daemon -K -q -p "$PIDFILE"
28	status=$?
29	if [ "$status" -eq 0 ]; then
30		echo "OK"
31	else
32		echo "FAIL"
33	fi
34	return "$status"
35}
36
37restart() {
38	stop
39	sleep 1
40	start
41}
42
43reload() {
44	printf 'Reloading %s: ' "$DAEMON"
45	start-stop-daemon -K -s HUP -q -p "$PIDFILE"
46	status=$?
47	if [ "$status" -eq 0 ]; then
48		echo "OK"
49	else
50		echo "FAIL"
51	fi
52	return "$status"
53}
54
55case "$1" in
56	start|stop|restart|reload)
57		"$1";;
58	*)
59		echo "Usage: $0 {start|stop|restart|reload}"
60		exit 1
61esac
62