#!/bin/bash

echo "A2DP Paring & Connection Script"

echo -e "SCANNING BLUETOOTH DEVICES ...."
echo -n "Please Put Headset in Pairing mode...press Enter.."

read nil
hcitool scan
echo "If device is not in the list press Enter"
echo "Copy the bluetooth address of the Headset and paste it below ="
read bdaddr
if [[ -z "${bdaddr}" ]]; then
   echo "Not a valid BD_ADDR"
   exit 0
fi
echo "Installing ~/.asoundrc Bluetooth device..."

sudo sed "s/sedbdaddr/$bdaddr/g" /usr/local/sbin/asoundrc > .asoundrc
cp .asoundrc ~/
echo " Done."

echo "Changing banshee ALSA setting to bluetooth"
soundbt.sh
echo "Done.\n"

echo "Starting AVRCP..."
sudo modprobe uinput
echo "AVRCP Started"

echo "Starting- Pairing with A2DP headset"
python /usr/local/sbin/agent.py hci0 $bdaddr 
echo "Pairing Done"

echo "Start Rhythmbox/Banshee Media player and enjoy the Music !"
