#!/bin/sh /etc/rc.common
## Bridge for Fonera 2.0x by monossido modified by basgys

START=41
## Get WAN iface from network file
waniface=$(tail -n +$(grep -n "config 'interface' 'wan'" /etc/config/network | cut -d":" -f1) /etc/config/network | grep -m1 "option 'ifname'" | awk '{print $3}' | tr -d "'")
## Get WAN IP from fon file
wanip=$(tail -n +$(grep -n "config 'wan'" /etc/config/fon | cut -d":" -f1) /etc/config/fon | grep -m1 "option 'ipaddr'" | awk '{print $3}' | tr -d "'")
## Get gateway IP from route table
gatewayip=$(route -n | grep $waniface | grep 'UG[ \t]' | awk '{print $2}') 

start() {
        ifconfig br-lan $wanip
        ifconfig $waniface 0.0.0.0
        brctl addif br-lan $waniface
        route add default gw $gatewayip
}
stop() {
        /etc/init.d/network restart
}
