#!/bin/bash

echo "HFP 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 Device and paste it below ="
read bdaddr
if [[ -z "${bdaddr}" ]]; then
   echo "Not a valid BD_ADDR"
   exit 0
fi

echo -n "Installing ~/.asoundrc Bluetooth device..."
sudo sed "s/sedbdaddr/$bdaddr/g" /usr/local/sbin/asoundrc > .asoundrc
cp .asoundrc ~/
echo " Done."

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

#Connect to HS
echo "Connecting to headset"
/usr/local/sbin/telephony roaming  yes
/usr/local/sbin/telephony connect $bdaddr
/usr/local/sbin/telephony signal 5
/usr/local/sbin/telephony CallSetupStatus 0 0
/usr/local/sbin/telephony lastDialMemory yes
echo "Inform PulseAudio about hfp"
pactl load-module module-alsa-source device=hfp

echo "Start VoIP(Skype) application !"
