View Single Post
Posts: 2,152 | Thanked: 1,490 times | Joined on Jan 2006 @ Czech Republic
#5
up script
Code:
#!/bin/sh
# use gainroot to become root and relaunch itself
if [ `id -u` != 0 ] ; then
#if not already root, call itself as root
        sudo gainroot <<EOF
$0 $*
EOF
        exit
fi
# real script follows
BTADDR='xx:xx:xx:xx:xx:xx'
IP=192.168.2.2
GW=192.168.2.1
NS=192.168.2.1
IFACE=bnep0

#insmod just to be sure
insmod /mnt/initfs/lib/modules/current/bnep.ko
#start PAN Bluetooth connection
pand --connect $BTADDR

# 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))
        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
else
    echo "Error: $IFACE not available."
fi
down script

Code:
#!/bin/sh
# use gainroot to become root and relaunch itself
if [ `id -u` != 0 ] ; then
#if not already root, call itself as root
        sudo gainroot <<EOF
$0 $*
EOF
        exit
fi
# real script follows
echo -n '' >/tmp/resolv.conf.lo
pand -K
sleep 1
rmmod bnep
you need to open dummy connection before executing 'up' script or DNS details wil get overwritten in /tmp/resolv/conf.lo