2014-08-18 13:09:17 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
CFG=/etc/board.json
|
|
|
|
|
|
|
|
. /usr/share/libubox/jshn.sh
|
|
|
|
|
2016-10-05 09:26:35 +00:00
|
|
|
[ -s $CFG ] || /bin/board_detect || exit 1
|
|
|
|
[ -s /etc/config/network -a -s /etc/config/system ] && exit 0
|
2014-08-18 13:09:17 +00:00
|
|
|
|
2020-11-03 16:43:22 +00:00
|
|
|
generate_bridge() {
|
|
|
|
local name=$1
|
2020-11-28 10:43:47 +00:00
|
|
|
local macaddr=$2
|
2020-11-03 16:43:22 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
set network.$name=device
|
|
|
|
set network.$name.name=$name
|
|
|
|
set network.$name.type=bridge
|
|
|
|
EOF
|
2020-11-28 10:43:47 +00:00
|
|
|
if [ -n "$macaddr" ]; then
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
set network.$name.macaddr=$macaddr
|
|
|
|
EOF
|
|
|
|
fi
|
2020-11-03 16:43:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bridge_vlan_id=0
|
|
|
|
generate_bridge_vlan() {
|
2020-11-19 14:08:33 +00:00
|
|
|
local name=$1_vlan
|
|
|
|
local device=$2
|
|
|
|
local ports="$3"
|
2020-11-28 10:43:47 +00:00
|
|
|
local vlan="$4"
|
2020-11-03 16:43:22 +00:00
|
|
|
uci -q batch <<-EOF
|
2020-11-19 14:08:33 +00:00
|
|
|
set network.$name=bridge-vlan
|
|
|
|
set network.$name.device='$device'
|
2020-11-28 10:43:47 +00:00
|
|
|
set network.$name.vlan='$vlan'
|
2020-11-19 14:08:33 +00:00
|
|
|
set network.$name.ports='$ports'
|
2020-11-03 16:43:22 +00:00
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2014-08-18 13:09:17 +00:00
|
|
|
generate_static_network() {
|
2015-11-26 12:04:32 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete network.loopback
|
|
|
|
set network.loopback='interface'
|
2021-05-24 14:45:06 +00:00
|
|
|
set network.loopback.device='lo'
|
2015-11-26 12:04:32 +00:00
|
|
|
set network.loopback.proto='static'
|
|
|
|
set network.loopback.ipaddr='127.0.0.1'
|
|
|
|
set network.loopback.netmask='255.0.0.0'
|
|
|
|
EOF
|
2018-08-04 11:01:18 +00:00
|
|
|
[ -e /proc/sys/net/ipv6 ] && {
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete network.globals
|
|
|
|
set network.globals='globals'
|
|
|
|
set network.globals.ula_prefix='auto'
|
|
|
|
EOF
|
|
|
|
}
|
2015-12-04 09:56:55 +00:00
|
|
|
|
|
|
|
if json_is_a dsl object; then
|
|
|
|
json_select dsl
|
|
|
|
if json_is_a atmbridge object; then
|
|
|
|
json_select atmbridge
|
2018-01-08 12:12:20 +00:00
|
|
|
local vpi vci encaps payload nameprefix
|
|
|
|
json_get_vars vpi vci encaps payload nameprefix
|
2015-12-04 09:56:55 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete network.atm
|
|
|
|
set network.atm='atm-bridge'
|
|
|
|
set network.atm.vpi='$vpi'
|
|
|
|
set network.atm.vci='$vci'
|
|
|
|
set network.atm.encaps='$encaps'
|
|
|
|
set network.atm.payload='$payload'
|
2018-01-08 12:12:20 +00:00
|
|
|
set network.atm.nameprefix='$nameprefix'
|
2015-12-04 09:56:55 +00:00
|
|
|
EOF
|
|
|
|
json_select ..
|
|
|
|
fi
|
|
|
|
|
|
|
|
if json_is_a modem object; then
|
|
|
|
json_select modem
|
|
|
|
local type annex firmware tone xfer_mode
|
|
|
|
json_get_vars type annex firmware tone xfer_mode
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete network.dsl
|
2016-03-07 11:03:29 +00:00
|
|
|
set network.dsl='dsl'
|
2015-12-04 09:56:55 +00:00
|
|
|
set network.dsl.annex='$annex'
|
|
|
|
set network.dsl.firmware='$firmware'
|
|
|
|
set network.dsl.tone='$tone'
|
|
|
|
set network.dsl.xfer_mode='$xfer_mode'
|
|
|
|
EOF
|
|
|
|
json_select ..
|
|
|
|
fi
|
|
|
|
json_select ..
|
|
|
|
fi
|
2014-08-18 13:09:17 +00:00
|
|
|
}
|
|
|
|
|
2015-12-03 22:27:06 +00:00
|
|
|
addr_offset=2
|
2014-08-18 13:09:17 +00:00
|
|
|
generate_network() {
|
2021-05-24 14:45:06 +00:00
|
|
|
local ports device macaddr protocol type ipaddr netmask vlan
|
2020-11-03 16:43:22 +00:00
|
|
|
local bridge=$2
|
2014-08-18 13:09:17 +00:00
|
|
|
|
|
|
|
json_select network
|
2015-12-03 16:25:19 +00:00
|
|
|
json_select "$1"
|
2021-05-24 14:45:06 +00:00
|
|
|
json_get_vars device macaddr protocol ipaddr netmask vlan
|
2021-05-14 09:09:57 +00:00
|
|
|
json_get_values ports ports
|
2015-12-03 16:25:19 +00:00
|
|
|
json_select ..
|
2014-08-18 13:09:17 +00:00
|
|
|
json_select ..
|
|
|
|
|
2021-05-24 14:45:06 +00:00
|
|
|
[ -n "$device" -o -n "$ports" ] || return
|
2015-11-26 12:04:32 +00:00
|
|
|
|
2021-05-14 09:09:57 +00:00
|
|
|
# Force bridge for "lan" as it may have other devices (e.g. wireless)
|
|
|
|
# bridged
|
|
|
|
[ "$1" = "lan" -a -z "$ports" ] && {
|
2021-05-24 14:45:06 +00:00
|
|
|
ports="$device"
|
2021-05-14 09:09:57 +00:00
|
|
|
}
|
|
|
|
|
2021-05-23 11:30:58 +00:00
|
|
|
[ -n "$ports" -a -z "$bridge" ] && {
|
2021-05-15 19:06:27 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
add network device
|
2021-05-20 08:32:18 +00:00
|
|
|
set network.@device[-1].name='br-$1'
|
2021-05-15 19:06:27 +00:00
|
|
|
set network.@device[-1].type='bridge'
|
2021-05-24 05:46:12 +00:00
|
|
|
set network.@device[-1].macaddr='$macaddr'
|
2021-05-15 19:06:27 +00:00
|
|
|
EOF
|
|
|
|
for port in $ports; do uci add_list network.@device[-1].ports="$port"; done
|
2021-05-24 14:45:06 +00:00
|
|
|
device=br-$1
|
2021-05-15 19:06:27 +00:00
|
|
|
type=
|
2021-05-24 05:46:12 +00:00
|
|
|
macaddr=""
|
2021-05-14 09:09:57 +00:00
|
|
|
}
|
2015-11-26 12:04:32 +00:00
|
|
|
|
2020-11-03 16:43:22 +00:00
|
|
|
[ -n "$bridge" ] && {
|
2021-05-24 14:45:06 +00:00
|
|
|
[ -z "$ports" ] && ports="$device"
|
2020-11-28 10:43:47 +00:00
|
|
|
if [ -z "$vlan" ]; then
|
|
|
|
bridge_vlan_id=$((bridge_vlan_id + 1))
|
|
|
|
vlan=$bridge_vlan_id
|
|
|
|
fi
|
2021-05-23 11:30:58 +00:00
|
|
|
generate_bridge_vlan $1 $bridge "$ports" $vlan
|
2021-05-24 14:45:06 +00:00
|
|
|
device=$bridge.$vlan
|
2020-11-03 16:43:22 +00:00
|
|
|
type=""
|
|
|
|
}
|
|
|
|
|
2015-11-26 12:04:32 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete network.$1
|
|
|
|
set network.$1='interface'
|
2015-12-03 16:25:19 +00:00
|
|
|
set network.$1.type='$type'
|
2021-05-24 14:45:06 +00:00
|
|
|
set network.$1.device='$device'
|
2015-11-26 12:04:32 +00:00
|
|
|
set network.$1.proto='none'
|
2016-02-07 14:18:43 +00:00
|
|
|
EOF
|
|
|
|
|
2019-11-11 16:20:45 +00:00
|
|
|
if [ -n "$macaddr" ]; then
|
2021-05-24 14:45:06 +00:00
|
|
|
for name in $device; do
|
2019-11-11 16:20:45 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete network.$1_${name/./_}_dev
|
|
|
|
set network.$1_${name/./_}_dev='device'
|
|
|
|
set network.$1_${name/./_}_dev.name='$name'
|
|
|
|
set network.$1_${name/./_}_dev.macaddr='$macaddr'
|
|
|
|
EOF
|
|
|
|
done
|
|
|
|
fi
|
2015-11-26 12:04:32 +00:00
|
|
|
|
2015-12-03 22:27:06 +00:00
|
|
|
case "$protocol" in
|
|
|
|
static)
|
2016-04-17 12:49:54 +00:00
|
|
|
local ipad
|
2015-12-03 22:27:06 +00:00
|
|
|
case "$1" in
|
2016-04-17 12:49:54 +00:00
|
|
|
lan) ipad=${ipaddr:-"192.168.1.1"} ;;
|
|
|
|
*) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
|
2015-12-03 22:27:06 +00:00
|
|
|
esac
|
|
|
|
|
2016-04-17 12:49:54 +00:00
|
|
|
netm=${netmask:-"255.255.255.0"}
|
|
|
|
|
2015-11-26 12:04:32 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
set network.$1.proto='static'
|
2016-04-17 12:49:54 +00:00
|
|
|
set network.$1.ipaddr='$ipad'
|
|
|
|
set network.$1.netmask='$netm'
|
2015-11-26 12:04:32 +00:00
|
|
|
EOF
|
2018-08-04 11:01:18 +00:00
|
|
|
[ -e /proc/sys/net/ipv6 ] && uci set network.$1.ip6assign='60'
|
2014-08-18 13:09:17 +00:00
|
|
|
;;
|
2015-12-03 22:27:06 +00:00
|
|
|
|
|
|
|
dhcp)
|
|
|
|
# fixup IPv6 slave interface if parent is a bridge
|
2021-05-24 14:45:06 +00:00
|
|
|
[ "$type" = "bridge" ] && device="br-$1"
|
2015-12-03 22:27:06 +00:00
|
|
|
|
2018-08-04 11:01:18 +00:00
|
|
|
uci set network.$1.proto='dhcp'
|
|
|
|
[ -e /proc/sys/net/ipv6 ] && {
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete network.${1}6
|
|
|
|
set network.${1}6='interface'
|
2021-05-24 14:45:06 +00:00
|
|
|
set network.${1}6.device='$device'
|
2018-08-04 11:01:18 +00:00
|
|
|
set network.${1}6.proto='dhcpv6'
|
|
|
|
EOF
|
|
|
|
}
|
2015-12-04 09:56:55 +00:00
|
|
|
;;
|
|
|
|
|
|
|
|
pppoe)
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
set network.$1.proto='pppoe'
|
|
|
|
set network.$1.username='username'
|
|
|
|
set network.$1.password='password'
|
2015-11-26 12:04:32 +00:00
|
|
|
EOF
|
2018-08-04 11:01:18 +00:00
|
|
|
[ -e /proc/sys/net/ipv6 ] && {
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
set network.$1.ipv6='1'
|
|
|
|
delete network.${1}6
|
|
|
|
set network.${1}6='interface'
|
2021-05-24 14:45:06 +00:00
|
|
|
set network.${1}6.device='@${1}'
|
2018-08-04 11:01:18 +00:00
|
|
|
set network.${1}6.proto='dhcpv6'
|
|
|
|
EOF
|
|
|
|
}
|
2014-08-18 13:09:17 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2015-12-03 16:25:19 +00:00
|
|
|
generate_switch_vlans_ports() {
|
|
|
|
local switch="$1"
|
|
|
|
local port ports role roles num attr val
|
2015-11-26 12:04:32 +00:00
|
|
|
|
2015-12-03 16:25:19 +00:00
|
|
|
#
|
|
|
|
# autogenerate vlans
|
|
|
|
#
|
|
|
|
|
2016-05-06 03:23:43 +00:00
|
|
|
if json_is_a roles array; then
|
|
|
|
json_get_keys roles roles
|
|
|
|
json_select roles
|
2015-12-03 16:25:19 +00:00
|
|
|
|
2016-05-06 03:23:43 +00:00
|
|
|
for role in $roles; do
|
|
|
|
json_select "$role"
|
|
|
|
json_get_vars ports
|
|
|
|
json_select ..
|
2015-12-03 16:25:19 +00:00
|
|
|
|
2016-05-06 03:23:43 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
add network switch_vlan
|
|
|
|
set network.@switch_vlan[-1].device='$switch'
|
|
|
|
set network.@switch_vlan[-1].vlan='$role'
|
|
|
|
set network.@switch_vlan[-1].ports='$ports'
|
|
|
|
EOF
|
|
|
|
done
|
2014-08-18 13:09:17 +00:00
|
|
|
|
2016-05-06 03:23:43 +00:00
|
|
|
json_select ..
|
|
|
|
fi
|
2014-08-18 13:09:17 +00:00
|
|
|
|
|
|
|
|
2015-12-03 16:25:19 +00:00
|
|
|
#
|
|
|
|
# write port specific settings
|
|
|
|
#
|
2015-11-24 21:16:38 +00:00
|
|
|
|
2016-05-06 03:23:43 +00:00
|
|
|
if json_is_a ports array; then
|
|
|
|
json_get_keys ports ports
|
|
|
|
json_select ports
|
|
|
|
|
|
|
|
for port in $ports; do
|
|
|
|
json_select "$port"
|
|
|
|
json_get_vars num
|
|
|
|
|
|
|
|
if json_is_a attr object; then
|
|
|
|
json_get_keys attr attr
|
|
|
|
json_select attr
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
add network switch_port
|
|
|
|
set network.@switch_port[-1].device='$switch'
|
|
|
|
set network.@switch_port[-1].port=$num
|
|
|
|
EOF
|
|
|
|
|
|
|
|
for attr in $attr; do
|
|
|
|
json_get_var val "$attr"
|
|
|
|
uci -q set network.@switch_port[-1].$attr="$val"
|
|
|
|
done
|
|
|
|
json_select ..
|
|
|
|
fi
|
|
|
|
json_select ..
|
|
|
|
done
|
2015-11-24 21:16:38 +00:00
|
|
|
|
2015-12-03 16:25:19 +00:00
|
|
|
json_select ..
|
2016-05-06 03:23:43 +00:00
|
|
|
fi
|
2015-11-24 21:16:38 +00:00
|
|
|
}
|
|
|
|
|
2014-08-18 13:09:17 +00:00
|
|
|
generate_switch() {
|
2015-11-26 12:04:32 +00:00
|
|
|
local key="$1"
|
2014-08-18 13:09:17 +00:00
|
|
|
local vlans
|
|
|
|
|
|
|
|
json_select switch
|
2015-11-26 12:04:32 +00:00
|
|
|
json_select "$key"
|
2019-05-17 08:53:18 +00:00
|
|
|
json_get_vars enable reset blinkrate cpu_port \
|
|
|
|
ar8xxx_mib_type ar8xxx_mib_poll_interval
|
2014-08-18 13:09:17 +00:00
|
|
|
|
2015-11-26 12:04:32 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
add network switch
|
|
|
|
set network.@switch[-1].name='$key'
|
|
|
|
set network.@switch[-1].reset='$reset'
|
|
|
|
set network.@switch[-1].enable_vlan='$enable'
|
|
|
|
set network.@switch[-1].blinkrate='$blinkrate'
|
2019-05-17 08:53:18 +00:00
|
|
|
set network.@switch[-1].ar8xxx_mib_type='$ar8xxx_mib_type'
|
|
|
|
set network.@switch[-1].ar8xxx_mib_poll_interval='$ar8xxx_mib_poll_interval'
|
2015-11-26 12:04:32 +00:00
|
|
|
EOF
|
2015-11-24 21:16:38 +00:00
|
|
|
|
2015-12-03 16:25:19 +00:00
|
|
|
generate_switch_vlans_ports "$1"
|
2015-11-24 21:16:38 +00:00
|
|
|
|
2014-08-18 13:09:17 +00:00
|
|
|
json_select ..
|
|
|
|
json_select ..
|
|
|
|
}
|
|
|
|
|
2016-05-31 12:19:45 +00:00
|
|
|
generate_static_system() {
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete system.@system[0]
|
|
|
|
add system system
|
2017-11-07 08:45:50 +00:00
|
|
|
set system.@system[-1].hostname='OpenWrt'
|
2016-05-31 12:19:45 +00:00
|
|
|
set system.@system[-1].timezone='UTC'
|
|
|
|
set system.@system[-1].ttylogin='0'
|
2016-06-08 13:03:20 +00:00
|
|
|
set system.@system[-1].log_size='64'
|
2016-06-27 15:53:30 +00:00
|
|
|
set system.@system[-1].urandom_seed='0'
|
2016-05-31 12:19:45 +00:00
|
|
|
|
|
|
|
delete system.ntp
|
|
|
|
set system.ntp='timeserver'
|
|
|
|
set system.ntp.enabled='1'
|
|
|
|
set system.ntp.enable_server='0'
|
2017-11-07 08:45:50 +00:00
|
|
|
add_list system.ntp.server='0.openwrt.pool.ntp.org'
|
|
|
|
add_list system.ntp.server='1.openwrt.pool.ntp.org'
|
|
|
|
add_list system.ntp.server='2.openwrt.pool.ntp.org'
|
|
|
|
add_list system.ntp.server='3.openwrt.pool.ntp.org'
|
2016-05-31 12:19:45 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
if json_is_a system object; then
|
|
|
|
json_select system
|
2019-11-07 17:16:46 +00:00
|
|
|
local hostname
|
2016-05-31 12:19:45 +00:00
|
|
|
if json_get_var hostname hostname; then
|
|
|
|
uci -q set "system.@system[-1].hostname=$hostname"
|
|
|
|
fi
|
|
|
|
|
base-files: add support for compat_version on device
We regularly encounter the situation that devices are subject to
changes that will make them incompatible to previous versions.
Removing SUPPORTED_DEVICES will not really be helpful in most of these
cases, as this only helps after a rename.
To solve this situation, this patchset introduces a compatibility
version for devices. To complement the DEVICE_COMPAT_VERSION set
for the image to be flashed, this implements a compat_version on
the device, so it will have something to compare with the image.
The only viable way to achieve this seems to be via board.d files,
i.e. this is technically adding a compat version for the device's
config.
Like for the network setup, this will set up a command
ucidef_set_compat_version to set the compat_version in board.d.
This will then add a string to /etc/board.json, which will be
translated into uci system config by bin/config_generate.
By this, the compat_version, being a version of the config, will
also be exposed to the user.
As with DEVICE_COMPAT_VERSION, missing uci entry will be assumed
as compat_version "1.0", so we only need to add this if a device
needs to be bumped, e.g.
ucidef_set_compat_version "1.1"
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
2020-07-09 17:24:11 +00:00
|
|
|
local compat_version
|
|
|
|
if json_get_var compat_version compat_version; then
|
|
|
|
uci -q set "system.@system[-1].compat_version=$compat_version"
|
|
|
|
else
|
|
|
|
uci -q set "system.@system[-1].compat_version=1.0"
|
|
|
|
fi
|
|
|
|
|
2016-05-31 12:19:45 +00:00
|
|
|
if json_is_a ntpserver array; then
|
|
|
|
local keys key
|
|
|
|
json_get_keys keys ntpserver
|
|
|
|
json_select ntpserver
|
|
|
|
uci -q delete "system.ntp.server"
|
|
|
|
|
|
|
|
for key in $keys; do
|
|
|
|
local server
|
|
|
|
if json_get_var server "$key"; then
|
|
|
|
uci -q add_list "system.ntp.server=$server"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
json_select ..
|
|
|
|
fi
|
|
|
|
json_select ..
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-11-26 12:04:43 +00:00
|
|
|
generate_rssimon() {
|
|
|
|
local key="$1"
|
|
|
|
local cfg="rssid_$key"
|
|
|
|
local refresh threshold
|
|
|
|
|
|
|
|
json_select rssimon
|
|
|
|
json_select "$key"
|
|
|
|
json_get_vars refresh threshold
|
|
|
|
json_select ..
|
|
|
|
json_select ..
|
|
|
|
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete system.$cfg
|
|
|
|
set system.$cfg='rssid'
|
|
|
|
set system.$cfg.dev='$key'
|
|
|
|
set system.$cfg.refresh='$refresh'
|
|
|
|
set system.$cfg.threshold='$threshold'
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2014-08-18 13:09:17 +00:00
|
|
|
generate_led() {
|
2015-11-26 12:04:32 +00:00
|
|
|
local key="$1"
|
2014-08-18 13:09:17 +00:00
|
|
|
local cfg="led_$key"
|
|
|
|
|
|
|
|
json_select led
|
2015-11-26 12:04:32 +00:00
|
|
|
json_select "$key"
|
2015-11-26 13:53:02 +00:00
|
|
|
json_get_vars name sysfs type trigger default
|
2014-08-18 13:09:17 +00:00
|
|
|
|
2015-11-26 12:04:32 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete system.$cfg
|
|
|
|
set system.$cfg='led'
|
|
|
|
set system.$cfg.name='$name'
|
|
|
|
set system.$cfg.sysfs='$sysfs'
|
|
|
|
set system.$cfg.trigger='$trigger'
|
|
|
|
set system.$cfg.default='$default'
|
|
|
|
EOF
|
|
|
|
|
|
|
|
case "$type" in
|
2015-11-26 13:53:06 +00:00
|
|
|
gpio)
|
|
|
|
local gpio inverted
|
|
|
|
json_get_vars gpio inverted
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
set system.$cfg.trigger='gpio'
|
|
|
|
set system.$cfg.gpio='$gpio'
|
|
|
|
set system.$cfg.inverted='$inverted'
|
|
|
|
EOF
|
|
|
|
;;
|
|
|
|
|
2015-11-26 12:04:32 +00:00
|
|
|
netdev)
|
2016-02-26 14:49:17 +00:00
|
|
|
local device mode
|
|
|
|
json_get_vars device mode
|
2015-11-26 12:04:32 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
set system.$cfg.trigger='netdev'
|
2016-02-26 14:49:17 +00:00
|
|
|
set system.$cfg.mode='$mode'
|
2015-11-26 13:53:02 +00:00
|
|
|
set system.$cfg.dev='$device'
|
2015-11-26 12:04:32 +00:00
|
|
|
EOF
|
|
|
|
;;
|
2014-08-18 13:09:17 +00:00
|
|
|
|
2015-11-26 12:04:32 +00:00
|
|
|
usb)
|
2015-11-26 13:53:02 +00:00
|
|
|
local device
|
|
|
|
json_get_vars device
|
2015-11-26 12:04:32 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
set system.$cfg.trigger='usbdev'
|
|
|
|
set system.$cfg.interval='50'
|
2015-11-26 13:53:02 +00:00
|
|
|
set system.$cfg.dev='$device'
|
2015-11-26 12:04:32 +00:00
|
|
|
EOF
|
|
|
|
;;
|
2015-11-26 12:04:43 +00:00
|
|
|
|
2016-10-19 11:05:53 +00:00
|
|
|
usbport)
|
|
|
|
local ports port
|
|
|
|
json_get_values ports ports
|
|
|
|
uci set system.$cfg.trigger='usbport'
|
|
|
|
for port in $ports; do
|
|
|
|
uci add_list system.$cfg.port=$port
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
|
2015-11-26 12:04:43 +00:00
|
|
|
rssi)
|
2015-11-26 13:53:02 +00:00
|
|
|
local iface minq maxq offset factor
|
2015-11-26 12:04:43 +00:00
|
|
|
json_get_vars iface minq maxq offset factor
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
set system.$cfg.trigger='rssi'
|
|
|
|
set system.$cfg.iface='rssid_$iface'
|
|
|
|
set system.$cfg.minq='$minq'
|
|
|
|
set system.$cfg.maxq='$maxq'
|
|
|
|
set system.$cfg.offset='$offset'
|
|
|
|
set system.$cfg.factor='$factor'
|
|
|
|
EOF
|
|
|
|
;;
|
2015-11-26 13:53:02 +00:00
|
|
|
|
|
|
|
switch)
|
2018-09-21 22:38:40 +00:00
|
|
|
local port_mask speed_mask mode
|
|
|
|
json_get_vars port_mask speed_mask mode
|
2015-11-26 13:53:02 +00:00
|
|
|
uci -q batch <<-EOF
|
|
|
|
set system.$cfg.port_mask='$port_mask'
|
2016-02-25 13:31:29 +00:00
|
|
|
set system.$cfg.speed_mask='$speed_mask'
|
2018-09-21 22:38:40 +00:00
|
|
|
set system.$cfg.mode='$mode'
|
2015-11-26 13:53:02 +00:00
|
|
|
EOF
|
|
|
|
;;
|
2015-12-03 22:27:02 +00:00
|
|
|
|
2016-05-31 12:35:24 +00:00
|
|
|
portstate)
|
|
|
|
local port_state
|
|
|
|
json_get_vars port_state
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
set system.$cfg.port_state='$port_state'
|
|
|
|
EOF
|
|
|
|
;;
|
|
|
|
|
2016-02-25 10:14:16 +00:00
|
|
|
timer|oneshot)
|
2015-12-03 22:27:02 +00:00
|
|
|
local delayon delayoff
|
|
|
|
json_get_vars delayon delayoff
|
|
|
|
uci -q batch <<-EOF
|
2016-02-25 10:14:16 +00:00
|
|
|
set system.$cfg.trigger='$type'
|
2015-12-03 22:27:02 +00:00
|
|
|
set system.$cfg.delayon='$delayon'
|
|
|
|
set system.$cfg.delayoff='$delayoff'
|
|
|
|
EOF
|
|
|
|
;;
|
2014-08-18 13:09:17 +00:00
|
|
|
esac
|
2015-11-26 12:04:43 +00:00
|
|
|
|
|
|
|
json_select ..
|
|
|
|
json_select ..
|
2014-08-18 13:09:17 +00:00
|
|
|
}
|
|
|
|
|
2015-12-04 15:02:32 +00:00
|
|
|
generate_gpioswitch() {
|
|
|
|
local cfg="$1"
|
|
|
|
|
|
|
|
json_select gpioswitch
|
|
|
|
json_select "$cfg"
|
|
|
|
local name pin default
|
|
|
|
json_get_vars name pin default
|
|
|
|
uci -q batch <<-EOF
|
|
|
|
delete system.$cfg
|
|
|
|
set system.$cfg='gpio_switch'
|
|
|
|
set system.$cfg.name='$name'
|
|
|
|
set system.$cfg.gpio_pin='$pin'
|
2016-12-08 16:13:09 +00:00
|
|
|
set system.$cfg.value='$default'
|
2015-12-04 15:02:32 +00:00
|
|
|
EOF
|
|
|
|
json_select ..
|
|
|
|
json_select ..
|
|
|
|
}
|
|
|
|
|
2014-08-18 13:09:17 +00:00
|
|
|
json_init
|
|
|
|
json_load "$(cat ${CFG})"
|
|
|
|
|
2020-04-30 19:29:09 +00:00
|
|
|
umask 077
|
|
|
|
|
2016-10-05 09:26:35 +00:00
|
|
|
if [ ! -s /etc/config/network ]; then
|
2020-11-28 10:43:47 +00:00
|
|
|
bridge_name=""
|
2016-05-31 12:47:30 +00:00
|
|
|
touch /etc/config/network
|
|
|
|
generate_static_network
|
2014-08-18 13:09:17 +00:00
|
|
|
|
2020-11-03 16:43:22 +00:00
|
|
|
json_get_vars bridge
|
2020-11-28 10:43:47 +00:00
|
|
|
[ -n "$bridge" ] && {
|
|
|
|
json_select bridge
|
|
|
|
json_get_vars name macaddr
|
|
|
|
generate_bridge "$name" "$macaddr"
|
|
|
|
json_select ..
|
|
|
|
bridge_name=$name
|
|
|
|
}
|
2020-11-03 16:43:22 +00:00
|
|
|
|
2016-05-31 12:47:30 +00:00
|
|
|
json_get_keys keys network
|
2020-11-28 10:43:47 +00:00
|
|
|
for key in $keys; do generate_network $key $bridge_name; done
|
2014-08-18 13:09:17 +00:00
|
|
|
|
2016-05-31 12:47:30 +00:00
|
|
|
json_get_keys keys switch
|
|
|
|
for key in $keys; do generate_switch $key; done
|
|
|
|
fi
|
2014-08-18 13:09:17 +00:00
|
|
|
|
2016-10-05 09:26:35 +00:00
|
|
|
if [ ! -s /etc/config/system ]; then
|
2016-05-31 12:47:30 +00:00
|
|
|
touch /etc/config/system
|
|
|
|
generate_static_system
|
2016-05-31 12:19:45 +00:00
|
|
|
|
2016-05-31 12:47:30 +00:00
|
|
|
json_get_keys keys rssimon
|
|
|
|
for key in $keys; do generate_rssimon $key; done
|
2016-05-31 12:19:45 +00:00
|
|
|
|
2016-05-31 12:47:30 +00:00
|
|
|
json_get_keys keys gpioswitch
|
|
|
|
for key in $keys; do generate_gpioswitch $key; done
|
2014-08-18 13:09:17 +00:00
|
|
|
|
2016-05-31 12:47:30 +00:00
|
|
|
json_get_keys keys led
|
|
|
|
for key in $keys; do generate_led $key; done
|
2016-06-08 05:32:30 +00:00
|
|
|
fi
|
2014-08-18 13:09:17 +00:00
|
|
|
uci commit
|