#!/bin/bash

echo "HID Paring & Connection Script"

echo -e "SCANNING BLUETOOTH DEVICES ...."
echo -n "Please Put HID device 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 HID Device and paste it below ="
read bdaddr
if [[ -z "${bdaddr}" ]]; then
   echo "Not a valid BD_ADDR"
   exit 0
fi

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

echo -e "Creating a connection\n"
sudo sed "s/sedbdaddr/$bdaddr/g" /usr/local/sbin/hidpy > hid.py
sudo cp hid.py /usr/local/sbin/
python /usr/local/sbin/hid.py 

hcitool con
echo -e "Connection done"

echo "Play with your Bluetooth HID device !"
