port-management: move port population to uci-defaults

This commit is contained in:
Sukru Senli 2020-03-29 13:51:24 +02:00
parent 8660069566
commit 696b4b063a

View file

@ -0,0 +1,53 @@
#!/bin/sh
. /lib/network/utils.sh
populate_config(){
if [ -s "/etc/config/ports" ]; then
if uci -q get ports.@ethport[0] >/dev/null; then
# return if there is any valid content
return 0
else
rm -f /etc/config/ports
fi
fi
touch /etc/config/ports
local portorder="$(db -q get hw.board.ethernetPortOrder)"
for port in $portorder; do
uci add ports ethport
uci rename ports.@ethport[-1]="$(interfacename $port)"
uci set ports.@ethport[-1].enabled=1
uci set ports.@ethport[-1].name="$(interfacename $port)"
uci set ports.@ethport[-1].ifname="$port"
uci set ports.@ethport[-1].speed=1000
uci set ports.@ethport[-1].duplex="full"
uci set ports.@ethport[-1].autoneg=1
uci set ports.@ethport[-1].eee=0
if [ "$(db -q get hw.board.ethernetWanPort)" = "$port" ]; then
uci set ports.@ethport[-1].pause=1
uci set ports.@ethport[-1].uplink=1
else
uci set ports.@ethport[-1].pause=0
fi
done
local fiberorder="$(db -q get hw.board.fiberPortOrder)"
for fiber in $fiberorder; do
uci add ports sfpport
uci rename ports.@sfpport[-1]="$(fibername $fiber)"
uci set ports.@sfpport[-1].enabled=1
uci set ports.@sfpport[-1].name="$(fibername $fiber)"
uci set ports.@sfpport[-1].ifname="$fiber"
uci set ports.@sfpport[-1].speed=1000
uci set ports.@sfpport[-1].duplex="full"
uci set ports.@sfpport[-1].autoneg=1
uci set ports.@sfpport[-1].eee=0
done
uci commit ports
[ $DEBUG ] && cat /etc/config/ports
}
[ -f /sbin/db -a -f /lib/db/config/hw ] && populate_config