#!/bin/bash

CARRIER_FILE=""

if [ -f /etc/ppp/default_provider ] ; then
    CARRIER_FILE=$(cat /etc/ppp/default_provider)
    if [ ! -f /etc/ppp/peers/$CARRIER_FILE ] ; then
        echo "ERROR: /etc/ppp/peers/$CARRIER_FILE does not exist!"
        exit 1
    fi
elif [ "$#" -eq 0 ] ; then
    # if they just called this via "callvz", then for legacy 
    # support, just assume it's telit-verizon for them.
    CARRIER_FILE="telit-verizon"
fi

if [[ -e /dev/nimbelink-0 ]] ; then
    python /usr/local/bin/nimbelink-prepare-for-use.py
    sleep 1
fi

pppd call $CARRIER_FILE &

sleep 1
VZW_PID=`pidof pppd`

while kill -0 $VZW_PID 2>&1
do
      sleep 1
done

sleep 5

/etc/ppp/peers/ppp-force-disconnect

