gluon-core: fall back to eth0 for the primary MAC address when there is no WLAN device
This commit is contained in:
parent
2dea903120
commit
c45a0bcdc1
@ -1,16 +1,34 @@
|
|||||||
#!/usr/bin/lua
|
#!/usr/bin/lua
|
||||||
|
|
||||||
local sysconfig = require 'gluon.sysconfig'
|
local sysconfig = require 'gluon.sysconfig'
|
||||||
|
|
||||||
|
|
||||||
|
if sysconfig.primary_mac then
|
||||||
|
os.exit(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local platform = require 'gluon.platform'
|
local platform = require 'gluon.platform'
|
||||||
|
|
||||||
local fs = require 'luci.fs'
|
local fs = require 'luci.fs'
|
||||||
local util = require 'luci.util'
|
local util = require 'luci.util'
|
||||||
|
|
||||||
|
|
||||||
if not sysconfig.primary_mac then
|
local try_files = {
|
||||||
|
'/sys/class/ieee80211/phy0/macaddress',
|
||||||
|
'/sys/class/net/eth0/address',
|
||||||
|
}
|
||||||
|
|
||||||
if platform.match('ar71xx', 'generic', {'tl-wdr3600', 'tl-wdr4300'}) then
|
if platform.match('ar71xx', 'generic', {'tl-wdr3600', 'tl-wdr4300'}) then
|
||||||
sysconfig.primary_mac = util.trim(fs.readfile('/sys/class/ieee80211/phy1/macaddress'))
|
table.insert(try_files, 1, '/sys/class/ieee80211/phy1/macaddress')
|
||||||
else
|
end
|
||||||
sysconfig.primary_mac = util.trim(fs.readfile('/sys/class/ieee80211/phy0/macaddress'))
|
|
||||||
|
|
||||||
|
for _, file in ipairs(try_files) do
|
||||||
|
local addr = fs.readfile(file)
|
||||||
|
|
||||||
|
if addr then
|
||||||
|
sysconfig.primary_mac = util.trim(addr)
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user