#!/bin/bash # # Init file for Bluez Alsa A2DP sink [ -x /usr/bin/bluealsa ] || exit 1 [ -x /usr/bin/bluetoothctl ] || exit 1 # Read configuration . /etc/default/bluez-alsa start() { echo -n "Starting bluez-alsa: /usr/bin/a2dp-agent " /usr/bin/a2dp-agent & # Turn bluetooth on and set discoverable. echo -e 'power on\ndiscoverable on\nquit' | bluetoothctl >/dev/null # Start the daemon echo -n -e "\n /usr/bin/bluealsa ${OPTIONS} " /usr/bin/bluealsa ${OPTIONS} >/dev/null 2>/dev/null & sleep 1 echo -n -e "\n /usr/bin/bluealsa-aplay ${ADEVICE}" /usr/bin/bluealsa-aplay ${ADEVICE} --profile-a2dp --pcm-buffer-time=170000 --pcm-period-time=10000 00:00:00:00:00:00 >/dev/null 2>/dev/null & echo } stop() { echo -n "Shutting down bluez-alsa: " [ ! -z "$(pidof /usr/bin/bluealsa-aplay)" ] && kill $(pidof /usr/bin/bluealsa-aplay) [ ! -z "$(pidof /usr/bin/bluealsa)" ] && kill $(pidof /usr/bin/bluealsa) [ ! -z "$(pgrep a2dp-agent)" ] && kill $(pgrep a2dp-agent) echo } restart(){ stop sleep 1 start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) if [ -z "$(pidof -x /usr/bin/a2dp-agent)" ]; then echo "bluez-alsa: not running" else echo "bluez-alsa a2dp-agent: running with pid $(pidof -x /usr/bin/a2dp-agent)" if [ -z "$(pidof /usr/bin/bluealsa)" ]; then echo " bluealsa: not running" else echo " bluealsa: running with pid $(pidof /usr/bin/bluealsa)" fi if [ -z "$(pidof /usr/bin/bluealsa-aplay)" ]; then echo " bluealsa-aplay: not running" else echo " bluealsa-aplay: running with pid $(pidof /usr/bin/bluealsa-aplay)" fi fi ;; *) echo "Usage: $0 {start|stop|restart|status}" esac