iopsys-feed/port-management/files/etc/init.d/port_management

75 lines
1.7 KiB
Bash
Executable file

#!/bin/sh /etc/rc.common
START=15
USE_PROCD=1
. /lib/functions.sh
include /lib/network
check_for_config(){
if [ -s "/etc/config/ports" ]
then
if uci -q get ports.@ethport[0] >/dev/null #are there any valid content then continue
then
return 0
else
rm -f /etc/config/ports
fi
fi
touch /etc/config/ports
local portorder="$(db 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].name="$(interfacename $port)"
uci set ports.@ethport[-1].ifname=$port
uci set ports.@ethport[-1].speed='auto'
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 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].name="$(fibername $fiber)"
uci set ports.@sfpport[-1].ifname=$fiber
uci set ports.@sfpport[-1].speed='auto'
uci set ports.@sfpport[-1].pause=1
done
uci commit ports
[ $DEBUG ] && cat /etc/config/ports
}
configure_ethports(){
local port ifname pause speed
name=$1
config_get speed $name speed
config_get ifname $name ifname
config_get pause $name pause
set_port_speed $ifname $speed $name
set_port_pause $ifname $pause
}
start_service() {
[ -f /sbin/db -a -f /lib/db/config/hw ] && check_for_config
[ -f /lib/network/port.sh ] || return
config_load ports
config_foreach configure_ethports ethport
}
service_triggers() {
procd_add_reload_trigger ports
}