gluon-core: replace nixio with luaposix and luabitops
This commit is contained in:
parent
60a0e78a4a
commit
fd10d7cbb0
@ -14,7 +14,7 @@ define Package/gluon-core
|
||||
TITLE:=Base files of Gluon
|
||||
DEPENDS:= \
|
||||
+gluon-site +libgluonutil +libiwinfo-lua +lua-platform-info +lua-simple-uci +lua-hash +lua-jsonc \
|
||||
+luci-lib-nixio +vxlan +odhcp6c +firewall +pretty-hostname
|
||||
+luabitop +luaposix +luci-lib-nixio +vxlan +odhcp6c +firewall +pretty-hostname
|
||||
endef
|
||||
|
||||
define Package/gluon-core/description
|
||||
|
@ -1,10 +1,10 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local fs = require 'nixio.fs'
|
||||
local sysconfig = require 'gluon.sysconfig'
|
||||
local unistd = require 'posix.unistd'
|
||||
|
||||
|
||||
if fs.stat('/lib/gluon/version/core') and not sysconfig.gluon_version then
|
||||
if unistd.access('/lib/gluon/version/core') and not sysconfig.gluon_version then
|
||||
-- This isn't an initial upgrade, so set gluon_version
|
||||
sysconfig.gluon_version = ''
|
||||
end
|
||||
|
@ -1,9 +1,9 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local fs = require 'nixio.fs'
|
||||
local unistd = require 'posix.unistd'
|
||||
|
||||
|
||||
if not fs.access('/lib/gluon/domains/') then
|
||||
if not unistd.access('/lib/gluon/domains/') then
|
||||
return
|
||||
end
|
||||
|
||||
@ -11,7 +11,7 @@ end
|
||||
local uci = require('simple-uci').cursor()
|
||||
|
||||
local domain = uci:get('gluon', 'core', 'domain')
|
||||
if domain and not fs.access('/lib/gluon/domains/' .. domain .. '.json') then
|
||||
if domain and not unistd.access('/lib/gluon/domains/' .. domain .. '.json') then
|
||||
io.stderr:write(string.format("Warning: invalid mesh domain '%s' configured, resetting to default...\n", domain))
|
||||
domain = nil
|
||||
end
|
||||
|
@ -11,8 +11,6 @@ end
|
||||
local util = require 'gluon.util'
|
||||
local platform = require 'gluon.platform'
|
||||
|
||||
local fs = require 'nixio.fs'
|
||||
|
||||
|
||||
local try_files = {
|
||||
'/sys/class/net/eth0/address'
|
||||
@ -52,7 +50,7 @@ end
|
||||
|
||||
|
||||
for _, file in ipairs(try_files) do
|
||||
local addr = fs.readfile(file)
|
||||
local addr = util.readfile(file)
|
||||
|
||||
if addr then
|
||||
sysconfig.primary_mac = util.trim(addr)
|
||||
|
@ -12,15 +12,15 @@ local util = require 'gluon.util'
|
||||
local platform = require 'gluon.platform'
|
||||
local site = require 'gluon.site'
|
||||
|
||||
local fs = require 'nixio.fs'
|
||||
local uci = require('simple-uci').cursor()
|
||||
local unistd = require 'posix.unistd'
|
||||
|
||||
|
||||
local function iface_exists(ifaces)
|
||||
if not ifaces then return nil end
|
||||
|
||||
for iface in ifaces:gmatch('%S+') do
|
||||
if fs.access('/sys/class/net/' .. iface:gsub('%..*$', '')) then
|
||||
if unistd.access('/sys/class/net/' .. iface:gsub('%..*$', '')) then
|
||||
return ifaces
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local fs = require 'nixio.fs'
|
||||
local unistd = require 'posix.unistd'
|
||||
|
||||
if not fs.access('/etc/opkg/distfeeds.conf') then
|
||||
if not unistd.access('/etc/opkg/distfeeds.conf') then
|
||||
os.exit(0)
|
||||
end
|
||||
|
||||
@ -22,8 +22,8 @@ subst['%%A'] = f:read()
|
||||
f:close()
|
||||
|
||||
subst['%%GS'] = site.site_code()
|
||||
subst['%%GV'] = util.trim(fs.readfile('/lib/gluon/gluon-version'))
|
||||
subst['%%GR'] = util.trim(fs.readfile('/lib/gluon/release'))
|
||||
subst['%%GV'] = util.trim(util.readfile('/lib/gluon/gluon-version'))
|
||||
subst['%%GR'] = util.trim(util.readfile('/lib/gluon/release'))
|
||||
|
||||
local prefix = subst['%%d'] .. '_'
|
||||
|
||||
|
@ -2,10 +2,9 @@
|
||||
|
||||
local sysconfig = require 'gluon.sysconfig'
|
||||
|
||||
local fs = require 'nixio.fs'
|
||||
local util = require 'gluon.util'
|
||||
|
||||
|
||||
-- Save the Gluon version in the sysconfig so we know which version we
|
||||
-- upgraded from after the next upgrade
|
||||
sysconfig.gluon_version = util.trim(fs.readfile('/lib/gluon/gluon-version'))
|
||||
sysconfig.gluon_version = util.trim(util.readfile('/lib/gluon/gluon-version'))
|
||||
|
@ -22,11 +22,11 @@ local ipairs = ipairs
|
||||
local pairs = pairs
|
||||
local table = table
|
||||
|
||||
local nixio = require 'nixio'
|
||||
local bit = require 'bit'
|
||||
local posix_glob = require 'posix.glob'
|
||||
local hash = require 'hash'
|
||||
local sysconfig = require 'gluon.sysconfig'
|
||||
local site = require 'gluon.site'
|
||||
local fs = require 'nixio.fs'
|
||||
|
||||
|
||||
module 'gluon.util'
|
||||
@ -77,14 +77,24 @@ function replace_prefix(file, prefix, add)
|
||||
os.rename(tmp, file)
|
||||
end
|
||||
|
||||
function exec(command)
|
||||
local pp = io.popen(command)
|
||||
local data = pp:read("*a")
|
||||
pp:close()
|
||||
local function readall(f)
|
||||
if not f then
|
||||
return nil
|
||||
end
|
||||
|
||||
local data = f:read('*a')
|
||||
f:close()
|
||||
return data
|
||||
end
|
||||
|
||||
function readfile(file)
|
||||
return readall(io.open(file))
|
||||
end
|
||||
|
||||
function exec(command)
|
||||
return readall(io.popen(command))
|
||||
end
|
||||
|
||||
function node_id()
|
||||
return string.gsub(sysconfig.primary_mac, ':', '')
|
||||
end
|
||||
@ -120,20 +130,25 @@ function get_mesh_devices(uconn)
|
||||
return devices
|
||||
end
|
||||
|
||||
local function find_phy_by_path(path)
|
||||
for phy in fs.glob('/sys/devices/' .. path .. '/ieee80211/phy*') do
|
||||
return phy:match('([^/]+)$')
|
||||
-- Safe glob: returns an empty table when the glob fails because of
|
||||
-- a non-existing path
|
||||
function glob(pattern)
|
||||
return posix_glob.glob(pattern) or {}
|
||||
end
|
||||
|
||||
for phy in fs.glob('/sys/devices/platform/' .. path .. '/ieee80211/phy*') do
|
||||
local function find_phy_by_path(path)
|
||||
local phy = glob('/sys/devices/' .. path .. '/ieee80211/phy*')[1]
|
||||
or glob('/sys/devices/platform/' .. path .. '/ieee80211/phy*')[1]
|
||||
|
||||
if phy then
|
||||
return phy:match('([^/]+)$')
|
||||
end
|
||||
end
|
||||
|
||||
local function find_phy_by_macaddr(macaddr)
|
||||
local addr = macaddr:lower()
|
||||
for file in fs.glob('/sys/class/ieee80211/*/macaddress') do
|
||||
if trim(fs.readfile(file)) == addr then
|
||||
for _, file in ipairs(glob('/sys/class/ieee80211/*/macaddress')) do
|
||||
if trim(readfile(file)) == addr then
|
||||
return file:match('([^/]+)/macaddress$')
|
||||
end
|
||||
end
|
||||
@ -181,14 +196,14 @@ function generate_mac(i)
|
||||
m1 = tonumber(m1, 16)
|
||||
m6 = tonumber(m6, 16)
|
||||
|
||||
m1 = nixio.bit.bor(m1, 0x02) -- set locally administered bit
|
||||
m1 = nixio.bit.band(m1, 0xFE) -- unset the multicast bit
|
||||
m1 = bit.bor(m1, 0x02) -- set locally administered bit
|
||||
m1 = bit.band(m1, 0xFE) -- unset the multicast bit
|
||||
|
||||
-- It's necessary that the first 45 bits of the MAC address don't
|
||||
-- vary on a single hardware interface, since some chips are using
|
||||
-- a hardware MAC filter. (e.g 'rt305x')
|
||||
|
||||
m6 = nixio.bit.band(m6, 0xF8) -- zero the last three bits (space needed for counting)
|
||||
m6 = bit.band(m6, 0xF8) -- zero the last three bits (space needed for counting)
|
||||
m6 = m6 + i -- add virtual interface id
|
||||
|
||||
return string.format('%02x:%s:%s:%s:%s:%02x', m1, m2, m3, m4, m5, m6)
|
||||
|
Loading…
Reference in New Issue
Block a user