op_bluetooth: Fixed state-restoring on startup
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_bluetooth.sh
1 #!/bin/sh
2 #
3 # Released under the GPL
4
5 INTERFACE="`hciconfig | grep "^hci" | cut -d ':' -f 1`"
6 LOCK=".op_btenabled"
7 cd "$HOME"
8
9 if [ "$1" = "startup" ]; then
10         [ -f "$LOCK" ] && sudo /usr/sbin/hciconfig "$INTERFACE" up pscan 1>/dev/null && sudo /usr/sbin/bluetoothd || echo "Bluetooth: User has not enabled Bluetooth." 
11
12 else
13         
14         # Figure out if Bluetooth is running or not
15         
16         if hciconfig "$INTERFACE" | grep UP &>/dev/null
17         then
18                 notify-send -u normal "Bluetooth" "Bluetooth is being disabled..." -i blueman -t 5000
19                 sudo /usr/sbin/hciconfig ${INTERFACE} down 1>/dev/null
20                 rm -f "$LOCK"
21         else
22                 pgrep bluetoothd
23                 echo $INTERFACE
24                 if [ $? -ne 1 ]; then
25                         notify-send -u normal "Bluetooth" "Bluetooth is being enabled..." -i blueman -t 5000
26                         sudo /usr/sbin/hciconfig ${INTERFACE} down 1>/dev/null
27                         sudo /usr/sbin/hciconfig ${INTERFACE} up pscan 1>/dev/null
28                         sudo /usr/sbin/bluetoothd 1>/dev/null
29                         touch "$LOCK"
30
31                 fi
32         fi
33 fi