#!/bin/sh
# Filename:      grml-btnets
# Purpose:       Program to do something
# Authors:       grml-team (grml.org), (c) Michael Gebetsroither <gebi@grml.org>
# Bug-Reports:   see http://grml.org/bugs/
# License:       This file is licensed under the GPL v2.
################################################################################


###
### __INCLUDES
###
. /etc/grml/sh-lib
#. /etc/grml/sysexits-sh



###
### __VARIABLES
###

verbose_=0
PIN_FILE_='/etc/bluetooth/pin'  # pin for bluetooth server services


###
### __FUNCTIONS
###

function printUsage
{
    cat <<EOT
Usage: "$PROG_NAME__" [OPTIONS] <command>

$PROG_NAME__ is the client config program for ip over bluetooth

COMMANDS:
   help             This help text
   start            Start service
   stop             Stop service
   <default>        start

OPTIONS:
   -p <pin>     The bluetooth pin (not implemented yet)
   -v           verbose (show what is going on, v++)
   -h           this help text

EOT
}


function actionStart
{
    pand -S -E -Q10
    echo -n "waiting for connection: "
    while [ true ]; do
        pand -l |grep "bnep0" 2>&1 >/dev/null
        ret_=$?
        if [ $ret_ == '0' ]; then
            break
        fi
        echo -n '.'
        sleep 1
    done
    echo "done"
    dhclient bnep0
}

function actionStop
{
    pand -K
}



###
### __MAIN
###

cat >&2 <<EOT
not implemented yet!!

please use grml-btnets or grml-btnetc:
    server -> grml-btnets
    client -> grml-btnetc

EOT
exit 1

while getopts "p:hv" opt; do
    case "$opt" in
        p) BTPIN_="${OPTARG}" ;;
        h) printUsage; exit 0 ;;
        v) let verbose_=$verbose_+1 ;;
        ?) printUsage; exit 64 ;;
    esac
done
shift $(($OPTIND - 1))  # set ARGV to the first not parsed commandline parameter
setVerbose $verbose_

case "$1" in
    help)   printUsage; exit 0 ;;
esac

checkRoot die "You have to be root to use this program"
disableSyslog


case "$1" in
    start) actionStart ;;
    stop) actionStop ;;
    "") actionStart ;;
    *) printUsage; exit 1;;
esac

exit 0

# END OF FILE
################################################################################
# vim:foldmethod=marker

