bt.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
function isdev {
if [ -a /dev/rfcomm0 ]; then
echo "1"
else
echo "0"
fi
}
function cleanup {
zenity --question --text "Want a clean up?"
if [ "$?" == "0" ]; then
rm -rf /tmp/rfcomm.conf
mv /tmp/rfcomm.conf.bak /etc/bluetooth/rfcomm.conf
rfcomm release 0
zenity --info --text="Done!"
else
exit
fi
}
if [ `head -n 1 /proc/acpi/ibm/bluetooth | awk '{print $2}'` = "enabled" ]; then
ANSWER=`zenity --list --column Type --text "What type of connection?" "Existing" "New host"`
if [ "$ANSWER" == "New host" ]; then
cp /etc/bluetooth/rfcomm.conf /tmp/rfcomm.conf.bak
NAME=$(zenity --entry --text "Device name?" --entry-text "");
DEV=`hcitool scan --refresh |grep $NAME|grep -oe '[0-9A-F]\{2\}\(:[0-9A-F]\{2\}\)\{5\}'`
CHANNEL=`sdptool search DUN $DEV | grep -E 'Channel:\ '|awk -F: '{ print $2 }'`
cat /etc/bluetooth/rfcomm.conf | sed -e "s/channel.[0-9]/channel ${CHANNEL}/" -e "s/device.[0-9A-F]\{2\}\(:[0-9A-F]\{2\}\)\{5\}/device ${DEV}/" > /tmp/rfcomm.conf
cp /tmp/rfcomm.conf /etc/bluetooth/rfcomm.conf
zenity --info --text="Config fie modified!"
/etc/rc.d/bluetooth restart
zenity --info --text="Bluetooth service restarted!"
if [ `isdev` == "1" ]; then
rfcomm release 0
fi
rfcomm bind 0
gnome-ppp
cleanup
elif [ "$ANSWER" == "Existing" ]; then
if [ `isdev` == "1" ]; then
rfcomm release 0
fi
rfcomm bind 0
gnome-ppp
else
echo ""
fi
else
zenity --error --text="Turn on Bluetooth!"
fi