Openwrt/lib/function/uci-default.sh
The script generates the default configuration under/etc/config/:
#!/bin/sh # Copyright (C) openwrt.org ucidef_leds_changed=0 Ucidef_set_led_netdev () {local cfg= "led_$1"
Local name=$2 local sysfs=$3 local dev=$4 uci-q get system. $cfg && return 0 UCI batch <<eof set system. $cfg = ' led ' Set system. $cfg. Name= ' $name ' Set system. $cfg. sysfs= ' $SYSFS ' Set system. $cfg . trigger= ' Netdev ' Set system. $cfg. dev= ' $dev ' Set system. $cfg. mode= ' link tx rx ' EOF ucidef_leds_changed=1} ucidef
_set_led_usbdev () {local cfg= "led_$1" local name=$2 local sysfs=$3 local dev=$4 Uci-q get system. $cfg && return 0 UCI batch <<eof set system. $cfg = ' led ' Set system. $cfg. Name= ' $nam E ' set system. $cfg. sysfs= ' $SYSFS ' Set system. $cfg. Trigger= ' Usbdev ' Set system. $cfg. dev= ' $dev ' Set system. $cfg. Interval
= ' EOF ucidef_leds_changed=1} ucidef_set_led_wlan () {local cfg= ' led_$1 ' local name=$2 Local Sysfs=$3 LocAl trigger=$4 uci-q get system. $cfg && return 0 UCI batch <<eof set system. $cfg = ' led ' Set System. $cfg. Name= ' $name ' Set system. $cfg. sysfs= ' $SYSFS ' Set system. $cfg. trigger= ' $trigger ' EOF ucidef_leds_change D=1} ucidef_set_led_switch () {local cfg= "led_$1" local name=$2 local sysfs=$3 local tri Gger=$4 local port_mask=$5 uci-q get system. $cfg && return 0 UCI batch <<eof set System. $cfg = ' led ' Set system. $cfg. Name= ' $name ' Set system. $cfg. sysfs= ' $SYSFS ' Set system. $cfg. Trigger= ' $trigger ' Set System. $cfg. port_mask= ' $port _mask ' EOF ucidef_leds_changed=1} ucidef_set_led_default () {local cfg= ' led_ $ "Local name=$2 local sysfs=$3 local default=$4 uci-q get system. $cfg && Retur N 0 UCI Batch <<eof set system. $cfg = ' led ' Set system. $cfg. Name= ' $name ' Set system. $cfg. sysfs= ' $sysfs ' set S Ystem. $cfg. default= ' $default '
EOF ucidef_leds_changed=1} ucidef_set_led_rssi () {local cfg= "led_$1" local name=$2 Loc Al sysfs=$3 local iface=$4 local minq=$5 local maxq=$6 local offset=$7 local facto R=$8 uci-q get system. $cfg && return 0 UCI batch <<eof set system. $cfg = ' led ' Set system.$
Cfg.name= ' $name ' Set system. $cfg. sysfs= ' $SYSFS ' 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 ucidef_leds_changed=1} ucidef_set_led_timer () {local cfg= ' led_$1 ' local name=$2
Local sysfs=$3 local delayon=$4 local delayoff=$5 uci-q get system. $cfg && return 0 UCI batch <<eof set system. $cfg = ' led ' Set system. $cfg. Name= ' $name ' Set system. $cfg. sysfs= ' $sysfs ' Set Syst Em. $cfg. trigger= ' Timer ' set system.$cfg.delayon= ' $delayon ' Set system. $cfg. delayoff= ' $delayoff ' EOF ucidef_leds_changed=1} ucidef_set_led_mmc () { Local cfg= "led_$1" local name=$2 local sysfs=$3 local trigger=$4 uci-q get system. $cfg && return 0 UCI batch <<eof set system. $cfg = ' led ' Set system. $cfg. Name= ' $name ' Set system. $cfg . sysfs= ' $SYSFS ' Set system. $cfg. trigger= ' $trigger ' EOF ucidef_leds_changed=1} ucidef_set_rssimon () {loc Al dev= "$" local refresh= "$" local threshold= "$" local cfg= "Rssid_$dev" Uci-q get sy Stem. $cfg && return 0 UCI batch <<eof set system. $cfg = ' rssid ' Set system. $cfg. dev= ' $dev ' Set system
. $cfg. refresh= ' $refresh ' Set system. $cfg. threshold= ' $threshold ' EOF ucidef_leds_changed=1} ucidef_commit_leds () {["$UCIDEF _leds_changed" = "1"] && UCI Commit system} Ucidef_set_interface_loopback () {UCI B Atch <<eof Set NetWork.loopback= ' interface ' set Network.loopback.ifname= ' lo ' set network.loopback.proto= ' static ' Set Network.loopback.ipaddr= ' 127.0.0.1 ' Set network.loopback.netmask= ' 255.0.0.0 ' Set network.globals= ' globals ' Set
network.globals.ula_prefix= ' Auto ' EOF} ucidef_set_interface_raw () {Local cfg=$1 local ifname=$2 Local proto=${3:-"None"} UCI batch <<eof set network. $cfg = ' interface ' Set network. $cfg. Ifname= ' $ifname ' SE T network. $cfg. proto= ' $proto ' EOF} ucidef_set_interface_lan () {Local ifname=$1 UCI batch <<eof s ET network.lan= ' interface ' Set network.lan.ifname= ' $ifname ' set network.lan.force_link=1 set network.lan.type= '
Bridge ' Set network.lan.proto= ' static ' Set network.lan.ipaddr= ' 192.168.1.1 ' Set network.lan.netmask= ' 255.255.255.0 '
Set network.lan.ip6assign= ' EOF} Ucidef_set_interface_wan () {Local ifname=$1 UCI batch <<eof Set network.wan= ' interface ' Set network.wan.ifname= ' $ifname ' Set Network.waN.proto= ' DHCP ' set network.wan6= ' interface ' Set network.wan6.ifname= ' $ifname ' Set network.wan6.proto= ' DHCPv6 ' EOF} Ucidef_set_interfaces_lan_wan () {local lan_ifname=$1 local wan_ifname=$2 Ucidef_set_interface_la
N "$lan _ifname" Ucidef_set_interface_wan "$wan _ifname"} ucidef_set_interface_macaddr () {Local ifname=$1
Local mac=$2 UCI batch <<eof set network. $ifname. Macaddr= ' $mac ' EOF} ucidef_add_switch () { Local name=$1 local reset=$2 local enable=$3 UCI batch <<eof Add network switch set Netwo
RK. @switch [ -1].name= ' $name ' Set network. @switch [ -1].reset= ' $reset ' Set network. @switch [ -1].enable_vlan= ' $enable ' EOF} ucidef_add_switch_vlan () {Local device=$1 local vlan=$2 local ports=$3 UCI Batch & lt;<eof Add Network Switch_vlan Set network. @switch_vlan [ -1].device= ' $device ' Set network. @switch_vlan [ -1].vlan= ' $ VLAN ' Set network. @switch_vlan [ -1].ports= ' $Ports ' EOF} ucidef_add_switch_port () {Local device=$1 local port=$2 UCI batch <<eof add n Etwork switch_port Set Network. @switch_port [ -1].device= ' $device ' Set network. @switch_port [ -1].port= ' $port ' EOF}