#!/bin/bash

echo "FOSSwire A2DP Connection Script"
echo "Copyright 2008 FOSSwire.com. Released under the GPL3."
echo "GStreamer toggle script from http://wiki.debian.org/BluetoothAlsa\n"

echo "Making .a2dp in ~"
cd
mkdir -p .a2dp

echo -n "Getting a2dp.py connection script..."
cd .a2dp
wget -qr -O a2dppy http://files.fosswire.com/scripts/a2dp/a2dp
echo -e "  done.\n"

echo -e "\nWe're now going to scan for a bluetooth device. Please put your headset in pairing mode and press Enter."
read nil
hcitool scan
echo "Copy the address of your headphones above and paste it below:"
read macaddr
sed s/sedmac/$macaddr/ a2dppy > a2dp.py

echo -n "Installing .asoundrc Bluetooth device..."
cd
wget -qr -O .asoundrc http://files.fosswire.com/scripts/a2dp/asoundrc
echo " done."

echo -n "Installing autostart script in ~/.config/autostart..."
mkdir -p .config/autostart
cd .config/autostart
wget -qr -O a2dp-connect.desktop http://files.fosswire.com/scripts/a2dp/a2dp.desktop
echo " done."

#echo -n "Configuring PulseAudio..."
#if [ -e ~/.pulse ]
#then
#	cd ~/.pulse
#	wget -q -O default.pa http://files.fosswire.com/scripts/a2dp/default.pa
#	echo " done."
#else
#	echo " failed. Do you have PulseAudio?"
#fi

echo -n "Preparing optional GStreamer support..."
cd ~/.a2dp
wget -q -O toggle.sh http://files.fosswire.com/scripts/a2dp/togglesh
chmod +x toggle.sh
echo -e " done.\n"

echo "Starting up..."
python a2dp.py

echo "All set up! You will need to log out for the changes to take effect."
echo -e "Trust me, it won't work unless you do.\n"

echo "Thanks for reading FOSSwire!"
