瀏覽代碼

base-files: simplify setting device MAC

1. Move code above interface generation
   It results in more logical order. Device gets its config section
   above interface section.
2. Drop the loop
   We have separated code handling bridges now so $device should be
   guaranteed to contain a single device name.
3. Drop section name
   It's not required by netifd or LuCI & it's not needed by this script
   as $device contains a single device name now.

Signed-off-by: Rafał Miłecki <[email protected]>
Rafał Miłecki 4 年之前
父節點
當前提交
e002179a6d
共有 1 個文件被更改,包括 8 次插入11 次删除
  1. 8 11
      package/base-files/files/bin/config_generate

+ 8 - 11
package/base-files/files/bin/config_generate

@@ -133,6 +133,14 @@ generate_network() {
 		type=""
 		type=""
 	}
 	}
 
 
+	if [ -n "$macaddr" ]; then
+		uci -q batch <<-EOF
+			add network device
+			set network.@device[-1].name='$device'
+			set network.@device[-1].macaddr='$macaddr'
+		EOF
+	fi
+
 	uci -q batch <<-EOF
 	uci -q batch <<-EOF
 		delete network.$1
 		delete network.$1
 		set network.$1='interface'
 		set network.$1='interface'
@@ -141,17 +149,6 @@ generate_network() {
 		set network.$1.proto='none'
 		set network.$1.proto='none'
 	EOF
 	EOF
 
 
-	if [ -n "$macaddr" ]; then
-		for name in $device; do
-			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
-
 	case "$protocol" in
 	case "$protocol" in
 		static)
 		static)
 			local ipad
 			local ipad