base-files: setting device MAC

This commit is contained in:
Lienol 2024-07-15 20:39:44 +08:00
parent 99c4bceff7
commit a972bc8337

View File

@ -15,6 +15,7 @@ generate_bridge() {
set network.$name.name=$name
set network.$name.type=bridge
EOF
[ -z "$macaddr" ] && macaddr=$(echo "02:$(openssl rand -hex 5 | tr 'a-z' 'A-Z' | sed 's/\(..\)/\1:/g;s/:$//')")
if [ -n "$macaddr" ]; then
uci -q batch <<-EOF
set network.$name.macaddr=$macaddr
@ -103,6 +104,9 @@ generate_network() {
[ -n "$device" -o -n "$ports" ] || return
[ -z "$macaddr" ] && macaddr=$(cat /sys/class/net/${device}/address 2>/dev/null | tr 'a-z' 'A-Z')
[ -z "$macaddr" ] && macaddr=$(echo "02:$(openssl rand -hex 5 | tr 'a-z' 'A-Z' | sed 's/\(..\)/\1:/g;s/:$//')")
# Force bridge for "lan" as it may have other devices (e.g. wireless)
# bridged
[ "$1" = "lan" -a -z "$ports" ] && {
@ -114,6 +118,7 @@ generate_network() {
add network device
set network.@device[-1].name='br-$1'
set network.@device[-1].type='bridge'
set network.@device[-1].macaddr='$macaddr'
EOF
for port in $ports; do uci add_list network.@device[-1].ports="$port"; done
[ -n "$macaddr" ] && {