make code more compact

This commit is contained in:
Christof Schulze 2016-04-23 22:40:39 +02:00
parent 39998f543e
commit ae42e979c1

View File

@ -2,6 +2,7 @@
local uci = require('luci.model.uci').cursor()
local site = require 'gluon.site_config'
local interfaces='/lib/gluon/core/dynamic/interfaces'
if site.mesh_on_wan then
uci:section('babeld', 'interface', 'mesh_wan',
@ -13,27 +14,11 @@ if site.mesh_on_wan then
uci:add_to_set('firewall', 'mesh_babel', 'network', 'wan')
end
local interfaces='/lib/gluon/core/dynamic/interfaces'
function interfaces_exists(file)
local f = io.open(file, "rb")
if f then f:close() end
return f ~= nil
end
function lines_from(file)
if not interfaces_exists(file) then return {} end
lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end
local lines = lines_from(interfaces)
for line,interface in pairs(lines) do
uci:section('babeld', 'interface', line, { ifname = interface })
pcall( function()
for interface in io.lines(interfaces) do
uci:section('babeld', 'interface', interface, { ifname = interface })
end
end)
uci:add_to_set('firewall', 'mesh_babel', 'network', 'client')
uci:add_to_set('firewall', 'mesh_babel', 'network', 'local_node4')