base-files: compatible with old luci

This commit is contained in:
aiamadeus 2025-10-23 23:08:30 +08:00
parent dace6c0b75
commit f19009ba68
4 changed files with 13 additions and 72 deletions

View File

@ -3,7 +3,6 @@
CFG=/etc/board.json
. /usr/share/libubox/jshn.sh
. /lib/functions/ipv4.sh
[ -s $CFG ] || /bin/board_detect || exit 1
[ -s /etc/config/network -a -s /etc/config/system ] && exit 0
@ -43,16 +42,16 @@ generate_static_network() {
set network.loopback='interface'
set network.loopback.device='lo'
set network.loopback.proto='static'
add_list network.loopback.ipaddr='127.0.0.1/8'
delete network.globals
set network.globals='globals'
set network.globals.dhcp_default_duid='auto'
set network.loopback.ipaddr='127.0.0.1'
set network.loopback.netmask='255.0.0.0'
EOF
[ -e /proc/sys/net/ipv6 ] && {
uci -q batch <<-EOF
set network.globals.ula_prefix='auto'
EOF
}
[ -e /proc/sys/net/ipv6 ] && {
uci -q batch <<-EOF
delete network.globals
set network.globals='globals'
set network.globals.ula_prefix='auto'
EOF
}
if json_is_a dsl object; then
json_select dsl
@ -161,19 +160,18 @@ generate_network() {
case "$protocol" in
static)
local ipad netm prefix
local ipad
case "$1" in
lan) ipad=${ipaddr:-"192.168.1.1"} ;;
*) ipad=${ipaddr:-"192.168.$((addr_offset++)).1"} ;;
esac
netm=${netmask:-"255.255.255.0"}
str2ip netm "$netm"
netmask2prefix prefix "$netm"
uci -q batch <<-EOF
set network.$1.proto='static'
add_list network.$1.ipaddr='$ipad/$prefix'
set network.$1.ipaddr='$ipad'
set network.$1.netmask='$netm'
EOF
[ -e /proc/sys/net/ipv6 ] && uci set network.$1.ip6assign='60'
;;

View File

@ -10,6 +10,7 @@ uci_apply_defaults() {
cd /etc/uci-defaults || return 0
files="$(ls)"
[ -z "$files" ] && return 0
mkdir -p /tmp/.uci
applied=""
for file in $files; do
( . "./$(basename $file)" ) && applied="$applied $file"

View File

@ -1,49 +0,0 @@
. /lib/functions.sh
migrate_ports() {
local config="$1"
local type ports ifname
config_get type "$config" type
[ "$type" != "bridge" ] && return
config_get ports "$config" ports
[ -n "$ports" ] && return
config_get ifname "$config" ifname
[ -z "$ifname" ] && return
for port in $ifname; do
uci add_list network.$config.ports="$port"
done
uci delete network.$config.ifname
}
migrate_bridge() {
local config="$1"
local type ifname
config_get type "$config" type
[ "$type" != "bridge" ] && return
config_get ifname "$config" ifname
uci -q batch <<-EOF
add network device
set network.@device[-1].name='br-$config'
set network.@device[-1].type='bridge'
EOF
for port in $ifname; do
uci add_list network.@device[-1].ports="$port"
done
uci -q batch <<-EOF
delete network.$config.type
delete network.$config.ifname
set network.$config.device='br-$config'
EOF
}
config_load network
config_foreach migrate_ports device
config_foreach migrate_bridge interface

View File

@ -1,9 +0,0 @@
[ "$(uci -q get network.globals.dhcp_default_duid)" != "auto" ] && exit 0
uci -q batch <<-EOF >/dev/null
# DUID-UUID - RFC6355
set network.globals.dhcp_default_duid="$(hexdump -vn 16 -e '"0004" 2/2 "%x"' /dev/urandom)"
commit network
EOF
exit 0