diff options
Diffstat (limited to 'package/base-files/files/lib/functions/system.sh')
-rw-r--r-- | package/base-files/files/lib/functions/system.sh | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh index cb0508fe9c..be7efe4e2e 100644 --- a/package/base-files/files/lib/functions/system.sh +++ b/package/base-files/files/lib/functions/system.sh @@ -1,5 +1,7 @@ # Copyright (C) 2006-2013 OpenWrt.org +. /usr/share/libubox/jshn.sh + get_mac_binary() { local path="$1" local offset="$2" @@ -12,14 +14,41 @@ get_mac_binary() { hexdump -v -n 6 -s $offset -e '5/1 "%02x:" 1/1 "%02x"' $path 2>/dev/null } -get_mac_label() { +get_mac_label_dt() { local basepath="/proc/device-tree" local macdevice="$(cat "$basepath/aliases/label-mac-device" 2>/dev/null)" local macaddr - [ -n "$macdevice" ] && macaddr=$(get_mac_binary "$basepath/$macdevice/mac-address" 0 2>/dev/null) + [ -n "$macdevice" ] || return + + macaddr=$(get_mac_binary "$basepath/$macdevice/mac-address" 0 2>/dev/null) [ -n "$macaddr" ] || macaddr=$(get_mac_binary "$basepath/$macdevice/local-mac-address" 0 2>/dev/null) - [ -n "$macaddr" ] || macaddr=$(uci -q get system.@system[0].label_macaddr) + + echo $macaddr +} + +get_mac_label_json() { + local cfg="/etc/board.json" + local macaddr + + [ -s "$cfg" ] || return + + json_init + json_load "$(cat $cfg)" + if json_is_a system object; then + json_select system + json_get_var macaddr label_macaddr + json_select .. + fi + + echo $macaddr +} + +get_mac_label() { + local macaddr=$(get_mac_label_dt) + + [ -n "$macaddr" ] || macaddr=$(get_mac_label_json) + echo $macaddr } |