aredn/files/etc/init.d/local

77 lines
2.7 KiB
Bash
Executable File

#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org
START=99
boot() {
if [ ! -f /etc/aredn_include/ethmacfixup ]
then
mkdir -p /etc/aredn_include
touch /etc/aredn_include/ethmacfixup
local lanintf=`uci -q get 'network.lan.ifname'`
local wifiintf=`uci -q get 'network.wifi.ifname'`
local lanmac=`ifconfig $lanintf | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}'`
local wifimac=`ifconfig $wifiintf | grep -o -E '([[:xdigit:]]{2}:){5}[[:xdigit:]]{2}'`
local intlanmac=${lanmac//:/}
local intwanmac=${wifimac//:/}
local macdelta=$((0x$intwanmac - 0x$intlanmac))
# Deal with lan and wifi having same mac address (common on TP-Link)
# Deal with lan mac + ~10 = wifi mac address (common on Microtik and
# breaks OLSR if using derived IP addresses)
if [ $macdelta -le 10 ]
then
local wifimacdigit=`printf "%X" $(((0x${wifimac:9:2} + 1) % 256))`
local newmac=${wifimac:0:9}${wifimacdigit}${wifimac:11}
lanintf=${lanintf%%.*}
echo "" > /etc/aredn_include/ethmacfixup
echo "config interface 'setethmac'" >> /etc/aredn_include/ethmacfixup
echo -e "\toption\tifname\t'$lanintf'" >> /etc/aredn_include/ethmacfixup
echo -e "\toption\tproto\t'none'" >> /etc/aredn_include/ethmacfixup
echo -e "\toption\tmacaddr\t$newmac" >> /etc/aredn_include/ethmacfixup
uci set "network.setethmac=interface"
uci set "network.setethmac.ifname=$lanintf"
uci set "network.setethmac.proto=none"
uci set "network.setethmac.macaddr=$newmac"
uci commit
/etc/init.d/network reload
/etc/init.d/network restart
fi
fi
[ -x /usr/local/bin/bbhn-postupgrade ] && /usr/local/bin/bbhn-postupgrade
# setup nvram variables
[ -x /usr/local/bin/nvram-setup ] && /usr/local/bin/nvram-setup
# run mode specific setup
[ -x /etc/config/local ] && /etc/config/local
[ -x /etc/local/services ] && /etc/local/services
# set POE passthrough if available
local poevalue=$(uci -q get aredn.@poe[0].passthrough)
if [ -z "$poevalue" ]; then
local dpval=$(jsonfilter -e '@.gpioswitch.poe_passthrough.default' < /etc/board.json)
if [ ! -z "$dpval" ]; then
uci -q add aredn poe
uci -q set aredn.@poe[0].passthrough="$dpval"
uci -q commit aredn
poevalue=$dpval
fi
fi
/usr/local/bin/poe_passthrough "${poevalue}"
# set USB passthrough if available
local usbvalue=$(uci -q get aredn.@usb[0].passthrough)
if [ -z "$usbvalue" ]; then
local duval=$(jsonfilter -e '@.gpioswitch.usb_power_switch.default' < /etc/board.json)
uci -q add aredn usb
uci -q set aredn.@usb[0].passthrough="$duval"
uci -q commit aredn
usbvalue=$duval
fi
/usr/local/bin/usb_passthrough "${usbvalue}"
}