gluon-core: fall back to eth0 for the primary MAC address when there is no WLAN device

This commit is contained in:
Matthias Schiffer 2015-01-25 02:29:43 +01:00
parent 2dea903120
commit c45a0bcdc1

View File

@ -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 = {
if platform.match('ar71xx', 'generic', {'tl-wdr3600', 'tl-wdr4300'}) then '/sys/class/ieee80211/phy0/macaddress',
sysconfig.primary_mac = util.trim(fs.readfile('/sys/class/ieee80211/phy1/macaddress')) '/sys/class/net/eth0/address',
else }
sysconfig.primary_mac = util.trim(fs.readfile('/sys/class/ieee80211/phy0/macaddress'))
if platform.match('ar71xx', 'generic', {'tl-wdr3600', 'tl-wdr4300'}) then
table.insert(try_files, 1, '/sys/class/ieee80211/phy1/macaddress')
end
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