![]() |
2008-02-08
, 01:21
|
Posts: 1,097 |
Thanked: 650 times |
Joined on Nov 2007
|
#42
|
#!/bin/sh
# use gainroot to become root and relaunch itself
if [ `id -u` != 0 ] ; then
echo 'root'
#if not already root, call itself as root
exec sudo gainroot <<EOF
exec $0 $*
EOF
exit $?
else
echo 'notroot'
fi
# real script follows
BTADDR='00:12:34:AB:56:78' # replace with your BT Address of phone
BTNAME="Nil_blackjack" # user your Phone BT Name as assigned
#IP=192.168.2.2
#GW=192.168.2.1
NS=192.168.2.1
PAN_ROLE=NAP # remote PAN role, one of NAP, GN
infoprint(){
DBUS_SESSION_BUS_ADDRESS='unixath=/tmp/session_bus_socket' dbus-send --session --print-reply --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint "string:$*" &
}
dbus_method(){
local dest=$1
shift
DBUS_REPLY=$(dbus-send 2>&1 --system --type=method_call --print-reply --dest="$dest" $* )
}
dbus_result(){
echo $DBUS_REPLY | cut -d ' ' -f 7 | tr -d \"
}
find_connection(){
#find or create connection
if dbus_method org.bluez /org/bluez org.bluez.Manager.ActivateService string:network ; then
NET_BUS=$(dbus_result)
# echo destination $NET_BUS
if dbus_method "${NET_BUS}" /org/bluez/network org.bluez.network.Manager.FindConnection string:"${BTADDR}" ; then
CONN=$(dbus_result)
else
if dbus_method "${NET_BUS}" /org/bluez/network org.bluez.network.Manager.CreateConnection string:"${BTADDR}" string:"$PAN_ROLE" ; then
CONN=$(dbus_result)
fi
fi
fi
}
bnep_start(){
#find_connection
if [ "$CONN" != "" ] ; then
echo connection $CONN
if dbus_method "${NET_BUS}" ${CONN} org.bluez.network.Connection.Connect ; then
BNEPDEV=$(dbus_result)
echo connected to $BNEPDEV
#ifconfig $BNEPDEV $IP up
#if route -n | grep -q '^0.0.0.0' ; then
# echo "default gateway already set, skipping GW and DNS setting"
#else
# route add default gw $GW
# echo "nameserver $NS" >/tmp/resolv.conf.lo
#fi
udhcpc -i $BNEPDEV
[ -t 1 ] || infoprint "Connected to $BTNAME"
fi
fi
}
bnep_stop(){
#find_connection
if [ "$CONN" != "" ] ; then
echo connection $CONN
if dbus_method "${NET_BUS}" ${CONN} org.bluez.network.Connection.Disconnect ; then
echo "OK, bringing down"
echo -n '' >/tmp/resolv.conf.lo
[ -t 1 ] || infoprint "$BTNAME disconnected"
fi
fi
}
echo "Searching for $BTADDR ..."
[ -t 1 ] || infoprint "Searching for $BTADDR"
find_connection
if [ "$CONN" = "" ] ; then
echo $DBUS_REPLY
echo "Setting up connection to $BTADDR failed"
[ -t 1 ] || infoprint "Connection to $BTADDR failed"
exit
fi
COMMAND=$1
if [ "$COMMAND" = "" ] ; then
dbus_method "${NET_BUS}" ${CONN} org.bluez.network.Connection.IsConnected
if [ "$(dbus_result)" = "true" ] ; then
COMMAND=stop
else
COMMAND=start
fi
echo $COMMAND
fi
case $COMMAND in
start) bnep_start ;;
stop) bnep_stop ;;
esac
The Following User Says Thank You to nilchak For This Useful Post: | ||
![]() |
2008-02-08
, 01:25
|
Posts: 11 |
Thanked: 1 time |
Joined on Feb 2008
|
#43
|
![]() |
2008-02-08
, 17:45
|
Posts: 2 |
Thanked: 0 times |
Joined on Feb 2008
|
#44
|
![]() |
2008-02-08
, 20:49
|
Posts: 11 |
Thanked: 1 time |
Joined on Feb 2008
|
#45
|
![]() |
2008-02-08
, 22:17
|
Posts: 1,097 |
Thanked: 650 times |
Joined on Nov 2007
|
#46
|
![]() |
2008-02-08
, 23:20
|
Posts: 11 |
Thanked: 1 time |
Joined on Feb 2008
|
#47
|
![]() |
2008-02-09
, 00:53
|
Posts: 11 |
Thanked: 1 time |
Joined on Feb 2008
|
#48
|
![]() |
2008-02-09
, 07:59
|
Posts: 2,152 |
Thanked: 1,490 times |
Joined on Jan 2006
@ Czech Republic
|
#49
|
![]() |
2008-02-09
, 14:51
|
Posts: 9 |
Thanked: 0 times |
Joined on Jan 2008
|
#50
|
Everything works fine now .
I did make some changes to Fanoush's script, and since the last time updgraded my OS2008 to the last but one release (OS2008 1.2007.42-19). No BT hacks on my Blackjack itself (except I had my BJ unlocked recently before I made an international trip - but that should not be a contributor in any way to get things working).
Thanks for all the help.
I will get back home and list down my steps and the mods to the script itself, so that other Blackjack users might also benefit from it. (please give me some time).