Skip to content
Snippets Groups Projects
Commit 4249d65a authored by bobcanthelpyou's avatar bobcanthelpyou
Browse files

treewide: fix luacheck warnings

parent 80b6e7f1
No related branches found
No related tags found
No related merge requests found
Showing
with 45 additions and 46 deletions
...@@ -5,7 +5,7 @@ local file = '/etc/dropbear/authorized_keys' ...@@ -5,7 +5,7 @@ local file = '/etc/dropbear/authorized_keys'
local keys = {} local keys = {}
function load_keys() local function load_keys()
for line in io.lines(file) do for line in io.lines(file) do
keys[line] = true keys[line] = true
end end
......
...@@ -2,8 +2,6 @@ return function(form, uci) ...@@ -2,8 +2,6 @@ return function(form, uci)
local pkg_i18n = i18n 'gluon-config-mode-contact-info' local pkg_i18n = i18n 'gluon-config-mode-contact-info'
local site_i18n = i18n 'gluon-site' local site_i18n = i18n 'gluon-site'
local site = require 'gluon.site'
local owner = uci:get_first("gluon-node-info", "owner") local owner = uci:get_first("gluon-node-info", "owner")
local help = site_i18n._translate("gluon-config-mode:contact-help") or pkg_i18n.translate( local help = site_i18n._translate("gluon-config-mode:contact-help") or pkg_i18n.translate(
......
...@@ -7,7 +7,8 @@ return function(form, uci) ...@@ -7,7 +7,8 @@ return function(form, uci)
local util = require 'gluon.util' local util = require 'gluon.util'
local selected_domain = uci:get('gluon', 'core', 'domain') local selected_domain = uci:get('gluon', 'core', 'domain')
local configured = uci:get_first('gluon-setup-mode','setup_mode', 'configured') == '1' or (selected_domain ~= site.default_domain()) local configured = uci:get_first('gluon-setup-mode','setup_mode', 'configured') == '1' or
(selected_domain ~= site.default_domain())
local function hide_domain_code(domain, code) local function hide_domain_code(domain, code)
if configured and code == selected_domain then if configured and code == selected_domain then
......
...@@ -9,7 +9,8 @@ M.MapValue = osm.MapValue ...@@ -9,7 +9,8 @@ M.MapValue = osm.MapValue
function M.help(i18n) function M.help(i18n)
local pkg_i18n = i18n 'gluon-config-mode-geo-location-osm' local pkg_i18n = i18n 'gluon-config-mode-geo-location-osm'
return pkg_i18n.translate( return pkg_i18n.translate(
'You may also select the position on the map displayed below if your computer is connected to the internet at the moment.' 'You may also select the position on the map displayed below '
.. 'if your computer is connected to the internet at the moment.'
) )
end end
......
...@@ -43,7 +43,7 @@ return function(form, uci) ...@@ -43,7 +43,7 @@ return function(form, uci)
end end
end end
local map = {} local map
if osm then if osm then
map = s:option(osm.MapValue, "map", osm.options()) map = s:option(osm.MapValue, "map", osm.options())
map:depends(share_location, true) map:depends(share_location, true)
...@@ -56,7 +56,9 @@ return function(form, uci) ...@@ -56,7 +56,9 @@ return function(form, uci)
function o:write(data) function o:write(data)
uci:set("gluon-node-info", location, "latitude", data) uci:set("gluon-node-info", location, "latitude", data)
end end
if osm then
map.lat = o map.lat = o
end
o = s:option(Value, "longitude", pkg_i18n.translate("Longitude"), pkg_i18n.translatef("e.g. %s", "10.689901")) o = s:option(Value, "longitude", pkg_i18n.translate("Longitude"), pkg_i18n.translatef("e.g. %s", "10.689901"))
o.default = uci:get("gluon-node-info", location, "longitude") o.default = uci:get("gluon-node-info", location, "longitude")
...@@ -65,7 +67,9 @@ return function(form, uci) ...@@ -65,7 +67,9 @@ return function(form, uci)
function o:write(data) function o:write(data)
uci:set("gluon-node-info", location, "longitude", data) uci:set("gluon-node-info", location, "longitude", data)
end end
if osm then
map.lon = o map.lon = o
end
if show_altitude then if show_altitude then
o = s:option(Value, "altitude", o = s:option(Value, "altitude",
......
...@@ -14,7 +14,8 @@ return function(form, uci) ...@@ -14,7 +14,8 @@ return function(form, uci)
local current_hostname = pretty_hostname.get(uci) local current_hostname = pretty_hostname.get(uci)
local default_hostname = util.default_hostname() local default_hostname = util.default_hostname()
local configured = uci:get_first('gluon-setup-mode', 'setup_mode', 'configured', false) or (current_hostname ~= default_hostname) local configured = uci:get_first('gluon-setup-mode', 'setup_mode', 'configured', false) or
(current_hostname ~= default_hostname)
local s = form:section(Section) local s = form:section(Section)
local o = s:option(Value, "hostname", pkg_i18n.translate("Node name")) local o = s:option(Value, "hostname", pkg_i18n.translate("Node name"))
......
...@@ -8,7 +8,6 @@ if sysconfig.lan_ifname or sysconfig.wan_ifname then ...@@ -8,7 +8,6 @@ if sysconfig.lan_ifname or sysconfig.wan_ifname then
end end
local util = require 'gluon.util'
local platform = require 'gluon.platform' local platform = require 'gluon.platform'
local site = require 'gluon.site' local site = require 'gluon.site'
......
...@@ -15,7 +15,7 @@ local sysconfig = require 'gluon.sysconfig' ...@@ -15,7 +15,7 @@ local sysconfig = require 'gluon.sysconfig'
local platform = require 'gluon.platform' local platform = require 'gluon.platform'
local config = site.wifi5.outdoors('preset') local config = site.wifi5.outdoors('preset')
local outdoor = false local outdoor
if sysconfig.gluon_version then if sysconfig.gluon_version then
-- don't enable the outdoor mode after an upgrade -- don't enable the outdoor mode after an upgrade
......
...@@ -16,14 +16,12 @@ if not sysconfig.gluon_version then ...@@ -16,14 +16,12 @@ if not sysconfig.gluon_version then
-- capable of operating in the 2.4 GHz and 5 GHz band need -- capable of operating in the 2.4 GHz and 5 GHz band need
-- to be distributed evenly. -- to be distributed evenly.
local radio_band_count = {band24=0, band5=0} local radio_band_count = {band24=0, band5=0}
util.foreach_radio(uci, function(radio, index, config) util.foreach_radio(uci, function(radio)
local hwmodes = iwinfo.nl80211.hwmodelist(util.find_phy(radio)) local hwmodes = iwinfo.nl80211.hwmodelist(util.find_phy(radio))
if (hwmodes.a or hwmodes.ac) and hwmodes.g then if hwmodes.g and not (hwmodes.a or hwmodes.ac) then
-- Dualband - do nothing in this step
elseif hwmodes.g then
-- 2.4 GHz -- 2.4 GHz
radio_band_count["band24"] = radio_band_count["band24"] + 1 radio_band_count["band24"] = radio_band_count["band24"] + 1
elseif hwmodes.a or hwmodes.ac then elseif (hwmodes.a or hwmodes.ac) and not hwmodes.g then
-- 5 GHz -- 5 GHz
radio_band_count["band5"] = radio_band_count["band5"] + 1 radio_band_count["band5"] = radio_band_count["band5"] + 1
end end
...@@ -31,7 +29,7 @@ if not sysconfig.gluon_version then ...@@ -31,7 +29,7 @@ if not sysconfig.gluon_version then
-- Use the number of all fixed 2.4G GHz and 5 GHz radios to -- Use the number of all fixed 2.4G GHz and 5 GHz radios to
-- distribute dualband radios in this step. -- distribute dualband radios in this step.
util.foreach_radio(uci, function(radio, index, config) util.foreach_radio(uci, function(radio)
local radio_name = radio['.name'] local radio_name = radio['.name']
local hwmodes = iwinfo.nl80211.hwmodelist(util.find_phy(radio)) local hwmodes = iwinfo.nl80211.hwmodelist(util.find_phy(radio))
if (hwmodes.a or hwmodes.ac) and hwmodes.g then if (hwmodes.a or hwmodes.ac) and hwmodes.g then
......
...@@ -46,7 +46,7 @@ for line in io.lines('/etc/opkg/distfeeds.conf') do ...@@ -46,7 +46,7 @@ for line in io.lines('/etc/opkg/distfeeds.conf') do
table.insert(distfeeds, line) table.insert(distfeeds, line)
end end
local f = io.open('/etc/opkg/distfeeds.conf', 'w') f = io.open('/etc/opkg/distfeeds.conf', 'w')
for _, line in ipairs(distfeeds) do for _, line in ipairs(distfeeds) do
local name = line:match('^src/gz%s' .. prefix .. '(%S+)%s') local name = line:match('^src/gz%s' .. prefix .. '(%S+)%s')
...@@ -62,7 +62,7 @@ end ...@@ -62,7 +62,7 @@ end
f:close() f:close()
if next(extra) then if next(extra) then
local f = io.open('/etc/opkg/gluon.conf', 'w') f = io.open('/etc/opkg/gluon.conf', 'w')
for k, v in pairs(extra) do for k, v in pairs(extra) do
f:write(string.format('src/gz %s %s\n', k, replace_patterns(v))) f:write(string.format('src/gz %s %s\n', k, replace_patterns(v)))
......
...@@ -85,10 +85,9 @@ function M.mac_to_ip(prefix, mac) ...@@ -85,10 +85,9 @@ function M.mac_to_ip(prefix, mac)
local h3 = 0x100 * m5 + tonumber(m6, 16) local h3 = 0x100 * m5 + tonumber(m6, 16)
local h4 = 0x100 * tonumber(m7, 16) + tonumber(m8, 16) local h4 = 0x100 * tonumber(m7, 16) + tonumber(m8, 16)
local prefix, plen = string.match(prefix, '(.*)/(%d+)') prefix = string.match(prefix, '(.*)/%d+')
plen = tonumber(plen, 10)
local p1, p2, p3, p4, p5, p6, p7, p8 = M.IPv6(prefix) local p1, p2, p3, p4 = M.IPv6(prefix)
return string.format("%x:%x:%x:%x:%x:%x:%x:%x/%d", p1, p2, p3, p4, h1, h2, h3, h4, 128) return string.format("%x:%x:%x:%x:%x:%x:%x:%x/%d", p1, p2, p3, p4, h1, h2, h3, h4, 128)
end end
......
...@@ -157,7 +157,7 @@ function M.find_phy(config) ...@@ -157,7 +157,7 @@ function M.find_phy(config)
end end
end end
local function get_addresses(uci, radio) local function get_addresses(radio)
local phy = M.find_phy(radio) local phy = M.find_phy(radio)
if not phy then if not phy then
return function() end return function() end
...@@ -200,11 +200,11 @@ function M.generate_mac(i) ...@@ -200,11 +200,11 @@ function M.generate_mac(i)
return string.format('%02x:%s:%s:%s:%s:%02x', m1, m2, m3, m4, m5, m6) return string.format('%02x:%s:%s:%s:%s:%02x', m1, m2, m3, m4, m5, m6)
end end
local function get_wlan_mac_from_driver(uci, radio, vif) local function get_wlan_mac_from_driver(radio, vif)
local primary = sysconfig.primary_mac:lower() local primary = sysconfig.primary_mac:lower()
local addresses = {} local addresses = {}
for address in get_addresses(uci, radio) do for address in get_addresses(radio) do
if address:lower() ~= primary then if address:lower() ~= primary then
table.insert(addresses, address) table.insert(addresses, address)
end end
...@@ -222,8 +222,8 @@ local function get_wlan_mac_from_driver(uci, radio, vif) ...@@ -222,8 +222,8 @@ local function get_wlan_mac_from_driver(uci, radio, vif)
end end
end end
function M.get_wlan_mac(uci, radio, index, vif) function M.get_wlan_mac(_, radio, index, vif)
local addr = get_wlan_mac_from_driver(uci, radio, vif) local addr = get_wlan_mac_from_driver(radio, vif)
if addr then if addr then
return addr return addr
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
local site = require 'gluon.site' local site = require 'gluon.site'
local babelconf='/etc/gluon-babeld.conf' local babelconf='/etc/gluon-babeld.conf'
file = io.open(babelconf, "w") local file = io.open(babelconf, "w")
file:write("ipv6-subtrees true\n") file:write("ipv6-subtrees true\n")
file:write("reflect-kernel-metric true\n") file:write("reflect-kernel-metric true\n")
file:write("export-table 254\n") file:write("export-table 254\n")
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
local site = require 'gluon.site' local site = require 'gluon.site'
local sysconfig = require 'gluon.sysconfig'
local util = require 'gluon.util' local util = require 'gluon.util'
local uci = require('simple-uci').cursor() local uci = require('simple-uci').cursor()
...@@ -39,7 +38,7 @@ local networks = uci:get_list('firewall', 'mesh', 'network') ...@@ -39,7 +38,7 @@ local networks = uci:get_list('firewall', 'mesh', 'network')
util.add_to_set(networks, 'client') util.add_to_set(networks, 'client')
uci:set_list('firewall', 'mesh', 'network', networks) uci:set_list('firewall', 'mesh', 'network', networks)
local networks = uci:get_list('firewall', 'drop', 'network') networks = uci:get_list('firewall', 'drop', 'network')
util.remove_from_set(networks, 'client') util.remove_from_set(networks, 'client')
uci:set_list('firewall', 'drop', 'network', networks) uci:set_list('firewall', 'drop', 'network', networks)
......
...@@ -2,7 +2,8 @@ local fastd_methods = {'salsa2012+gmac', 'salsa2012+umac', 'null+salsa2012+gmac' ...@@ -2,7 +2,8 @@ local fastd_methods = {'salsa2012+gmac', 'salsa2012+umac', 'null+salsa2012+gmac'
need_array_of({'mesh_vpn', 'fastd', 'methods'}, fastd_methods) need_array_of({'mesh_vpn', 'fastd', 'methods'}, fastd_methods)
need_boolean(in_site({'mesh_vpn', 'fastd', 'configurable'}), false) need_boolean(in_site({'mesh_vpn', 'fastd', 'configurable'}), false)
need_one_of(in_site({'mesh_vpn', 'fastd', 'syslog_level'}), {'error', 'warn', 'info', 'verbose', 'debug', 'debug2'}, false) need_one_of(in_site({'mesh_vpn', 'fastd', 'syslog_level'}),
{'error', 'warn', 'info', 'verbose', 'debug', 'debug2'}, false)
local function check_peer(k) local function check_peer(k)
need_alphanumeric_key(k) need_alphanumeric_key(k)
......
if need_table(in_domain({'domain_switch'}), check_domain_switch, false) then if need_table(in_domain({'domain_switch'}), nil, false) then
need_domain_name(in_domain({'domain_switch', 'target_domain'})) need_domain_name(in_domain({'domain_switch', 'target_domain'}))
need_number(in_domain({'domain_switch', 'switch_after_offline_mins'})) need_number(in_domain({'domain_switch', 'switch_after_offline_mins'}))
need_number(in_domain({'domain_switch', 'switch_time'})) need_number(in_domain({'domain_switch', 'switch_time'}))
......
#!/usr/bin/lua #!/usr/bin/lua
local json = require 'jsonc'
local site = require 'gluon.site' local site = require 'gluon.site'
local unistd = require 'posix.unistd'
local cronfile = "/usr/lib/micron.d/gluon-scheduled-domain-switch" local cronfile = "/usr/lib/micron.d/gluon-scheduled-domain-switch"
......
...@@ -6,7 +6,7 @@ local util = require 'gluon.util' ...@@ -6,7 +6,7 @@ local util = require 'gluon.util'
local site = require 'gluon.site' local site = require 'gluon.site'
-- Returns true if node was offline long enough to perform domain switch -- Returns true if node was offline long enough to perform domain switch
function switch_after_min_reached() local function switch_after_min_reached()
if not unistd.access("/tmp/gluon_offline") then if not unistd.access("/tmp/gluon_offline") then
return false return false
end end
...@@ -33,7 +33,7 @@ function switch_after_min_reached() ...@@ -33,7 +33,7 @@ function switch_after_min_reached()
end end
-- Returns true in case switch time has passed -- Returns true in case switch time has passed
function switch_time_passed() local function switch_time_passed()
local current_time = os.time() local current_time = os.time()
local switch_time = site.domain_switch.switch_time() local switch_time = site.domain_switch.switch_time()
......
...@@ -15,10 +15,11 @@ package 'gluon-web-admin' ...@@ -15,10 +15,11 @@ package 'gluon-web-admin'
local util = require 'gluon.util' local util = require 'gluon.util'
local unistd = require 'posix.unistd' local unistd = require 'posix.unistd'
local file
local tmpfile = "/tmp/firmware.img" local tmpfile = "/tmp/firmware.img"
local function filehandler(meta, chunk, eof) local function filehandler(_, chunk, eof)
if not unistd.access(tmpfile) and not file and chunk and #chunk > 0 then if not unistd.access(tmpfile) and not file and chunk and #chunk > 0 then
file = io.open(tmpfile, "w") file = io.open(tmpfile, "w")
end end
...@@ -33,7 +34,6 @@ end ...@@ -33,7 +34,6 @@ end
local function action_upgrade(http, renderer) local function action_upgrade(http, renderer)
local fcntl = require 'posix.fcntl' local fcntl = require 'posix.fcntl'
local stat = require 'posix.sys.stat' local stat = require 'posix.sys.stat'
local wait = require 'posix.sys.wait'
local function fork_exec(argv) local function fork_exec(argv)
local pid = unistd.fork() local pid = unistd.fork()
...@@ -63,15 +63,15 @@ local function action_upgrade(http, renderer) ...@@ -63,15 +63,15 @@ local function action_upgrade(http, renderer)
end end
end end
local function image_supported(tmpfile) local function image_supported(supported_tmpfile)
return (os.execute(string.format("exec /sbin/sysupgrade -T %q >/dev/null", tmpfile)) == 0) return (os.execute(string.format("exec /sbin/sysupgrade -T %q >/dev/null", supported_tmpfile)) == 0)
end end
local function storage_size() local function storage_size()
local size = 0 local size = 0
if unistd.access("/proc/mtd") then if unistd.access("/proc/mtd") then
for l in io.lines("/proc/mtd") do for l in io.lines("/proc/mtd") do
local d, s, e, n = l:match('^([^%s]+)%s+([^%s]+)%s+([^%s]+)%s+"([^%s]+)"') local s, n = l:match('^[^%s]+%s+([^%s]+)%s+[^%s]+%s+"([^%s]+)"')
if n == "linux" then if n == "linux" then
size = tonumber(s, 16) size = tonumber(s, 16)
break break
...@@ -79,7 +79,7 @@ local function action_upgrade(http, renderer) ...@@ -79,7 +79,7 @@ local function action_upgrade(http, renderer)
end end
elseif unistd.access("/proc/partitions") then elseif unistd.access("/proc/partitions") then
for l in io.lines("/proc/partitions") do for l in io.lines("/proc/partitions") do
local x, y, b, n = l:match('^%s*(%d+)%s+(%d+)%s+([^%s]+)%s+([^%s]+)') local b, n = l:match('^%s*%d+%s+%d+%s+([^%s]+)%s+([^%s]+)')
if b and n and not n:match('[0-9]') then if b and n and not n:match('[0-9]') then
size = tonumber(b) * 1024 size = tonumber(b) * 1024
break break
...@@ -89,8 +89,8 @@ local function action_upgrade(http, renderer) ...@@ -89,8 +89,8 @@ local function action_upgrade(http, renderer)
return size return size
end end
local function image_checksum(tmpfile) local function image_checksum(checksum_tmpfile)
return (util.exec(string.format("exec sha256sum %q", tmpfile)):match("^([^%s]+)")) return (util.exec(string.format("exec sha256sum %q", checksum_tmpfile)):match("^([^%s]+)"))
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment