TIP bluetooth headset daemon and init script
From Gentoo Linux Wiki
| Terminals / Shells • Network • X Window System • Portage • System • Filesystems • Kernel • Other |
Contents |
[edit] Introduction
This TIP is here to bring you an init script starting btsco (or btsco2) and let you use your bluetooth headset. Cause btsco will exit if your headset is not switched on when the init script starts, there is a bash script that will act as a daemon, waiting for your headset to be switched on and then automatically start btsco.
If you want to use btsco2 this is not necessary, cause it will keep running even if your headset is switched of. In this case you only need the init script.
[edit] Requirements
In order to use this you will need alsa, bluetooth and your headset to be properly configured. Please follow these documentations to reach this:
- The Gentoo Linux ALSA Guide [1]
- The Gentoo Linux Bluetooth Guide [2]
- HOWTO use a bluetooth headset Bluetooth headset
[edit] Installation
[edit] Headset daemon
First we will get the bash script that will act as a daemon waiting for the headset being switched on.
Just copy/paste this file as root:
|
| File: /usr/local/bin/connect-to-headset.sh |
#!/bin/bash
source /etc/conf.d/headset
tail --pid $$ -fn 0 /var/log/messages | while read SYSLOG_IN
do
echo ${SYSLOG_IN} | grep -e 'hcid.*link_key_request' &> /dev/null
if [ $? -eq "0" ]
then
SYSLOG_IN="$(echo $SYSLOG_IN | sed 's/.*dba=//' | sed 's/)//')"
if [ "${SYSLOG_IN}" == "${BD_ADDRESS}" ]
then
btsco -f $BD_ADDRESS &> /dev/null
fi
fi
done
|
Now make the script executable:
|
[edit] Init script
Second we need the init script that lauches btsco(2) (and the just created script):
|
| File: /etc/init.d/headset |
#!/sbin/runscript
# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
depend()
{
need bluetooth alsasound
}
start()
{
ebegin "Connecting to your bluetooth headset"
if [ "${USE_BTSCO2}" == "TRUE" ]
then
start-stop-daemon --start --background --quiet \
--make-pidfile --pidfile /var/run/btsco2 \
--exec /usr/bin/btsco2 -- $BD_ADDRESS
else
start-stop-daemon --start --background --quiet \
--make-pidfile --pidfile /var/run/btsco \
--exec /usr/bin/btsco -- $BD_ADDRESS
start-stop-daemon --start --background \
--make-pidfile --pidfile /var/run/connect-to-headset.sh \
--exec /usr/local/bin/connect-to-headset.sh
fi
eend $?
}
stop()
{
ebegin "Killing bluetooth headset daemons"
start-stop-daemon --stop --pidfile /var/run/btsco2
start-stop-daemon --stop --pidfile /var/run/btsco
start-stop-daemon --stop --pidfile /var/run/connect-to-headset.sh
killall -9 btsco &> /dev/null
eend 0
}
restart()
{
svc_stop
svc_start
}
|
Now make the init script executable:
|
In addition, the init script and the daemon script, both require a config file. This file should provide the hardware address of your headset. Btsco will only be started for devices using this address. Please follow the headset guide Bluetooth headset#Configure the system if you haven't yet. You can also choose whether you want to use btsco or btsco2.
|
| File: /etc/conf.d/headset |
# # Config file for /etc/init.d/headset and connect-to-headset.sh scripts # # Your headsets hardware address as reported by 'hcitool inq' BD_ADDRESS="00:0F:F6:15:2D:E0" # Comment out if you want to use btsco, otherwise btsco2 is used USE_BTSCO2="TRUE" |
[edit] Usage
That's all we need for now :)
If you want the init script to be started with your system (*very* recommended). Please type:
|
To start it right now, just type:
|
... and switch on your headset. After a few seconds you will be able to use it.
