#!/bin/sh

DESTDIR="$HOME/Library/LaunchAgents"
SRCDIR="/AppleInternal/Library/Frameworks/BluetoothAutomation.framework/Resources/Services"
ERROR=0

[ -d "$DESTDIR" ] || mkdir -p $DESTDIR

for service in com.apple.bluetoothautomationbroker.plist com.apple.bluetoothautomation.plist com.apple.BluetoothAutomationAgent.plist; do
	[ -f $DESTDIR/$service ] && { launchctl unload -w $DESTDIR/$service 2>&1 | egrep "stat|nothing|Error" || echo "Unregistered BluetoothAutomation service ($service)." ; }
	cp $SRCDIR/$service $DESTDIR
	{ launchctl load -w $DESTDIR/$service 2>&1 | egrep -iq "stat|nothing|Error" ; } || echo "Registered BluetoothAutomation service ($service)."
done
