Editing configuration files with UCI

Which method to use? It's not clear.

network.@device[2]=device
network.@device[2].name='wan'
network.@device[2].macaddr='a1:b2:c3:d4:e5:f6'
network.@device[3]=device
network.@device[3].name='eth1'
network.@device[3].macaddr='a1:b2:c3:d4:e5:f6'
network.cfg080f15=device
network.cfg080f15.name='wan'
network.cfg080f15.macaddr='a1:b2:c3:d4:e5:f6'
network.cfg090f15=device
network.cfg090f15.name='eth1'
network.cfg090f15.macaddr='a1:b2:c3:d4:e5:f6'

Method 1

uci delete network.@device[2]

→ UCI default # Integrating custom settings

Method 2

uci delete network.cfg080f15

→[Forum] Help using uci-defaults to have firstboot configuration

Method 3

# <buildroot/files>/etc/uci-defaults/99-custom
delete_wan_device() {
   local config="$1"
   local device_name

   config_get device_name "$config" "name"

   if [ "$device_name" = "wan" ]
   then
      uci -q delete network."$config"
   fi 
}

. /lib/functions.sh
config_load network
config_foreach delete_wan_device device
uci commit network
service network restart

It should work as it seems to be executed as a shell script.

→ Using the Image Builder # Restricting root access