2015-05-15 23:54:16 -06:00
|
|
|
#!/bin/sh
|
|
|
|
# extract auto-generated first boot switch config settings
|
2022-08-16 13:03:13 -06:00
|
|
|
# and store them for future use. Support advanced user overrides.
|
2022-12-22 13:22:49 -07:00
|
|
|
ainclude="/etc/aredn_include"
|
|
|
|
mkdir -p $ainclude
|
|
|
|
|
2022-08-16 13:03:13 -06:00
|
|
|
if [ -f /etc/aredn_include/swconfig.user ]
|
|
|
|
then
|
|
|
|
cp /etc/aredn_include/swconfig.user /etc/aredn_include/swconfig
|
|
|
|
fi
|
2015-05-15 23:54:16 -06:00
|
|
|
if [ ! -f /etc/aredn_include/swconfig ]
|
|
|
|
then
|
2022-12-22 13:22:49 -07:00
|
|
|
touch $ainclude/swconfig
|
2015-05-15 23:54:16 -06:00
|
|
|
i=0
|
|
|
|
while true; do
|
|
|
|
uci -q get network.\@switch\[$i\] > /dev/null
|
2018-03-29 23:00:19 -06:00
|
|
|
status=$?
|
2015-05-15 23:54:16 -06:00
|
|
|
if [ $status == 1 ]
|
|
|
|
then
|
|
|
|
break
|
|
|
|
fi
|
2022-12-22 13:22:49 -07:00
|
|
|
echo "config switch" >> $ainclude/swconfig
|
|
|
|
echo " option name '`uci -q get network.\@switch\[$i\].name`'" >> $ainclude/swconfig
|
|
|
|
echo " option reset '`uci -q get network.\@switch\[$i\].reset`'" >> $ainclude/swconfig
|
|
|
|
echo " option enable_vlan '`uci -q get network.\@switch\[$i\].enable_vlan`'" >> $ainclude/swconfig
|
|
|
|
echo "" >> $ainclude/swconfig
|
2015-05-15 23:54:16 -06:00
|
|
|
let i++
|
|
|
|
done
|
|
|
|
|
|
|
|
i=0
|
|
|
|
while true; do
|
|
|
|
uci -q get network.\@switch_vlan\[$i\] > /dev/null
|
2018-03-29 23:00:19 -06:00
|
|
|
status=$?
|
2015-05-15 23:54:16 -06:00
|
|
|
if [ $status == 1 ]
|
|
|
|
then
|
|
|
|
break
|
|
|
|
fi
|
2022-12-22 13:22:49 -07:00
|
|
|
echo "config switch_vlan" >> $ainclude/swconfig
|
|
|
|
echo " option device '`uci -q get network.\@switch_vlan\[$i\].device`'" >> $ainclude/swconfig
|
|
|
|
echo " option vlan '`uci -q get network.\@switch_vlan\[$i\].vlan`'" >> $ainclude/swconfig
|
|
|
|
echo " option ports '`uci -q get network.\@switch_vlan\[$i\].ports`'" >> $ainclude/swconfig
|
|
|
|
echo "" >> $ainclude/swconfig
|
2015-05-15 23:54:16 -06:00
|
|
|
let i++
|
|
|
|
done
|
|
|
|
|
|
|
|
i=0
|
|
|
|
while true; do
|
|
|
|
uci -q get network.\@switch_port\[$i\] > /dev/null
|
2018-03-29 23:00:19 -06:00
|
|
|
status=$?
|
2015-05-15 23:54:16 -06:00
|
|
|
if [ $status == 1 ]
|
|
|
|
then
|
|
|
|
break
|
|
|
|
fi
|
2022-12-22 13:22:49 -07:00
|
|
|
echo "config switch_port" >> $ainclude/swconfig
|
|
|
|
echo " option device '`uci -q get network.\@switch_port\[$i\].device`'" >> $ainclude/swconfig
|
|
|
|
echo " option port '`uci -q get network.\@switch_port\[$i\].port`'" >> $ainclude/swconfig
|
|
|
|
echo " option pvid '`uci -q get network.\@switch_port\[$i\].pvid`'" >> $ainclude/swconfig
|
|
|
|
echo "" >> $ainclude/swconfig
|
2015-05-15 23:54:16 -06:00
|
|
|
let i++
|
|
|
|
done
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2023-01-15 00:07:22 -07:00
|
|
|
# Network setup done by node-setup
|
2022-12-22 13:22:49 -07:00
|
|
|
|
2015-05-15 23:54:16 -06:00
|
|
|
# Save system NET LED settings
|
2022-12-22 13:22:49 -07:00
|
|
|
if [ ! -f $ainclude/system_netled ]
|
2015-05-15 23:54:16 -06:00
|
|
|
then
|
2022-12-22 13:22:49 -07:00
|
|
|
touch $ainclude/system_netled
|
2015-05-15 23:54:16 -06:00
|
|
|
|
2022-12-22 13:22:49 -07:00
|
|
|
CFG=/etc/board.json
|
2018-03-30 00:55:55 -06:00
|
|
|
|
2022-12-22 13:22:49 -07:00
|
|
|
. /usr/share/libubox/jshn.sh
|
2018-03-30 00:55:55 -06:00
|
|
|
|
2022-12-22 13:22:49 -07:00
|
|
|
[ -s $CFG ] || /bin/board_detect || exit 1
|
2018-03-30 00:55:55 -06:00
|
|
|
|
2022-12-22 13:22:49 -07:00
|
|
|
generate_led() {
|
2018-03-30 00:55:55 -06:00
|
|
|
local key="$1"
|
|
|
|
local cfg="led_$key"
|
|
|
|
|
|
|
|
json_select led
|
|
|
|
json_select "$key"
|
|
|
|
json_get_vars name sysfs type trigger default
|
|
|
|
|
|
|
|
|
|
|
|
case "$type" in
|
|
|
|
gpio)
|
|
|
|
local gpio inverted
|
|
|
|
json_get_vars gpio inverted
|
|
|
|
;;
|
|
|
|
|
|
|
|
netdev)
|
|
|
|
local device mode
|
|
|
|
json_get_vars device mode
|
2022-12-22 13:22:49 -07:00
|
|
|
echo "config led 'led_$1'" >> $ainclude/system_netled
|
|
|
|
echo " option name '$name'" >> $ainclude/system_netled
|
|
|
|
echo " option sysfs '$sysfs'" >> $ainclude/system_netled
|
|
|
|
echo " option trigger 'netdev'" >> $ainclude/system_netled
|
|
|
|
echo " option mode '$mode'" >> $ainclude/system_netled
|
|
|
|
echo " option dev '$device'" >> $ainclude/system_netled
|
|
|
|
echo "" >> $ainclude/system_netled
|
2018-03-30 00:55:55 -06:00
|
|
|
;;
|
|
|
|
|
|
|
|
usb)
|
|
|
|
local device
|
|
|
|
json_get_vars device
|
|
|
|
;;
|
|
|
|
|
|
|
|
usbport)
|
|
|
|
local ports port
|
|
|
|
json_get_values ports ports
|
|
|
|
;;
|
|
|
|
|
|
|
|
rssi)
|
|
|
|
local iface minq maxq offset factor
|
|
|
|
json_get_vars iface minq maxq offset factor
|
|
|
|
;;
|
|
|
|
|
|
|
|
switch)
|
|
|
|
local port_mask speed_mask
|
|
|
|
json_get_vars port_mask speed_mask
|
2022-12-22 13:22:49 -07:00
|
|
|
echo "config led 'led_$1'" >> $ainclude/system_netled
|
|
|
|
echo " option name '$name'" >> $ainclude/system_netled
|
|
|
|
echo " option sysfs '$sysfs'" >> $ainclude/system_netled
|
|
|
|
echo " option trigger '$trigger'" >> $ainclude/system_netled
|
|
|
|
echo " option port_mask '$port_mask'" >> $ainclude/system_netled
|
|
|
|
echo "" >> $ainclude/system_netled
|
2018-03-30 00:55:55 -06:00
|
|
|
;;
|
|
|
|
|
|
|
|
portstate)
|
|
|
|
local port_state
|
|
|
|
json_get_vars port_state
|
|
|
|
;;
|
|
|
|
|
|
|
|
timer|oneshot)
|
|
|
|
local delayon delayoff
|
|
|
|
json_get_vars delayon delayoff
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
json_select ..
|
|
|
|
json_select ..
|
2022-12-22 13:22:49 -07:00
|
|
|
}
|
2018-03-30 00:55:55 -06:00
|
|
|
|
|
|
|
|
2022-12-22 13:22:49 -07:00
|
|
|
json_init
|
|
|
|
json_load "$(cat ${CFG})"
|
2018-03-30 00:55:55 -06:00
|
|
|
|
|
|
|
|
2022-12-22 13:22:49 -07:00
|
|
|
if [ ! -s $ainclude/system_netled ]; then
|
|
|
|
touch $ainclude/system_netled
|
2018-03-30 00:55:55 -06:00
|
|
|
|
|
|
|
json_get_keys keys led
|
|
|
|
for key in $keys; do generate_led $key; done
|
2022-12-22 13:22:49 -07:00
|
|
|
fi
|
2018-12-02 18:52:48 -07:00
|
|
|
fi
|
|
|
|
|
2015-05-15 23:54:16 -06:00
|
|
|
exit 0
|