#!/bin/sh
#
#	This script will configure network interfaces, VLAN's, and routes
#

GPIO=/usr/local/bin/telem/gpio.sh

eth1=/etc/init.d/network_eth1
eth2=/etc/init.d/network_eth2
eth3=/etc/init.d/network_eth3
eth4=/etc/init.d/network_eth4

usb_net_sh=/usr/local/bin/telem/usb-network.sh

start() {
    logger -s -p "user.info" -t "$0" "Configuring USB network"

    if [ ! -e /etc/.stamp_mactab ]; then
        ! rm /etc/mactab
    fi
    
    ! rm -rf /tmp/usb-net.lock
    
    test -e $eth1 && { 
        $usb_net_sh eth1 &
    }
    
    test -e $eth2 && { 
        $usb_net_sh eth2 &
    }
    
    test -e $eth3 && { 
        $usb_net_sh eth3 &
    }
    
    test -e $eth4 && { 
        $usb_net_sh eth4 &
    }
}



stop() {
    logger -s -p "user.info" -t "$0" "Taking USB network down"
    
    busybox killall -9 usb-network.sh
    
    test -e $eth1 && $eth1 stop
    test -e $eth2 && $eth2 stop
    test -e $eth3 && $eth3 stop
    test -e $eth4 && $eth4 stop
}



case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|reload)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
esac

exit $?
