View Single Post
Posts: 2,152 | Thanked: 1,490 times | Joined on Jan 2006 @ Czech Republic
#8
Originally Posted by Luna View Post
This is my modified PAN script which originated from one of our wonderful members (but embarassed that I forget who and cannotgivethe proper kudos)
Few bits are mine :-) Here is my current version, it is suitable as ON/OFF shortcut in menu since it toggles the state. Also prints infoprint when not run from terminal. Beware that long dbus-send line may be wrapped incorrectly, it is in fact single line. True that for GUI stuff in IT2007 it needs additional hacks instead of the DUMMY connection but it is good enough even for quick ssh into the device.

Code:
#!/bin/sh
# use gainroot to become root and relaunch itself
if [ `id -u` != 0 ] ; then
#if not already root, call itself as root
        exec sudo gainroot <<EOF
exec $0 $*
EOF
        exit $?
fi
# real script follows
BTADDR='00:16:41:B7:B9:07'
BTNAME="FRANTA"
IP=192.168.2.2
GW=192.168.2.1
NS=10.6.101.1
IFACE=bnep0

#thanks to inz on #maemo IRC channel for this
infoprint(){
dbus-send >/dev/null 2>&1 --system --print-reply --dest=com.nokia.statusbar /com/nokia/statusbar com.nokia.statusbar.system_note_infoprint "string:$*"
}

bnep_start(){
#insmod just to be sure
insmod /mnt/initfs/lib/modules/current/bnep.ko
#start PAN Bluetooth connection
pand --connect $BTADDR -d GN
# wait for the interface created by pand
s=60
echo -n "Waiting $s secs for $IFACE"
while [ $s -gt 0 ] ; do
        ifconfig $IFACE >/dev/null 2>&1 && break
        s=$((s-1))
        [ -t 1 ] && echo -n "."
        sleep 1
done
echo
if ifconfig $IFACE >/dev/null 2>&1 ; then
# bring it up
echo "OK, bringing $IFACE up"
ifconfig $IFACE $IP up
route add default gw $GW
echo "nameserver $NS" >/tmp/resolv.conf.lo
    [ -t 1 ] || infoprint "Connected to $BTNAME"
else
    echo "Error: $IFACE not available."
    [ -t 1 ] || infoprint "Connection failed"
fi
}

bnep_stop(){
echo "OK, bringing $IFACE down"
echo -n '' >/tmp/resolv.conf.lo
pand -K
sleep 1
rmmod bnep
[ -t 1 ] || infoprint "Disconnected"
}

COMMAND=$1
if [ "$COMMAND" = "" ] ; then
    if ifconfig $IFACE >/dev/null 2>&1 ; then
        COMMAND=stop
    else
        COMMAND=start
    fi
fi

case $COMMAND in
    start)      bnep_start ;;
    stop)       bnep_stop ;;
esac