diff --git a/package/gluon-authorized-keys/luasrc/lib/gluon/upgrade/100-authorized-keys b/package/gluon-authorized-keys/luasrc/lib/gluon/upgrade/100-authorized-keys
index 34efd0b8afb85ecc38a5c016ec3ea358d5733cc6..9f3040743073df7a47b6c960ceed7037bedac301 100755
--- a/package/gluon-authorized-keys/luasrc/lib/gluon/upgrade/100-authorized-keys
+++ b/package/gluon-authorized-keys/luasrc/lib/gluon/upgrade/100-authorized-keys
@@ -5,7 +5,7 @@ local file = '/etc/dropbear/authorized_keys'
 
 local keys = {}
 
-function load_keys()
+local function load_keys()
   for line in io.lines(file) do
     keys[line] = true
   end
diff --git a/package/gluon-config-mode-contact-info/luasrc/lib/gluon/config-mode/wizard/0500-contact-info.lua b/package/gluon-config-mode-contact-info/luasrc/lib/gluon/config-mode/wizard/0500-contact-info.lua
index 8309d87abc0f5d667272ae42e9133b6185a42738..a47b604371715df06bbdd4beaf90574531fa4d90 100644
--- a/package/gluon-config-mode-contact-info/luasrc/lib/gluon/config-mode/wizard/0500-contact-info.lua
+++ b/package/gluon-config-mode-contact-info/luasrc/lib/gluon/config-mode/wizard/0500-contact-info.lua
@@ -2,8 +2,6 @@ return function(form, uci)
 	local pkg_i18n = i18n 'gluon-config-mode-contact-info'
 	local site_i18n = i18n 'gluon-site'
 
-	local site = require 'gluon.site'
-
 	local owner = uci:get_first("gluon-node-info", "owner")
 
 	local help = site_i18n._translate("gluon-config-mode:contact-help") or pkg_i18n.translate(
diff --git a/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua b/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua
index 85977f68d552873633f16630299ec0acab578b73..14ba4c637280c69f82df298b701fbc8d1aceeb30 100644
--- a/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua
+++ b/package/gluon-config-mode-domain-select/luasrc/lib/gluon/config-mode/wizard/0200-domain-select.lua
@@ -7,7 +7,8 @@ return function(form, uci)
 	local util = require 'gluon.util'
 
 	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)
 		if configured and code == selected_domain then
diff --git a/package/gluon-config-mode-geo-location-osm/luasrc/usr/lib/lua/gluon/config-mode/geo-location-osm.lua b/package/gluon-config-mode-geo-location-osm/luasrc/usr/lib/lua/gluon/config-mode/geo-location-osm.lua
index 6cc6d65a55680fbe7c24dbd2638dd0b3228f4950..0ae5455580e3e7efbf5f27e9e7a038c2593ea6bd 100644
--- a/package/gluon-config-mode-geo-location-osm/luasrc/usr/lib/lua/gluon/config-mode/geo-location-osm.lua
+++ b/package/gluon-config-mode-geo-location-osm/luasrc/usr/lib/lua/gluon/config-mode/geo-location-osm.lua
@@ -9,7 +9,8 @@ M.MapValue = osm.MapValue
 function M.help(i18n)
 	local pkg_i18n = i18n 'gluon-config-mode-geo-location-osm'
 	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
 
diff --git a/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua b/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua
index 928b4c5a7cd8e79848693300775649dae4cd7c74..e2d0bdb700a294043c616a2b01fce6251cda8102 100644
--- a/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua
+++ b/package/gluon-config-mode-geo-location/luasrc/lib/gluon/config-mode/wizard/0400-geo-location.lua
@@ -43,7 +43,7 @@ return function(form, uci)
 		end
 	end
 
-	local map = {}
+	local map
 	if osm then
 		map = s:option(osm.MapValue, "map", osm.options())
 		map:depends(share_location, true)
@@ -56,7 +56,9 @@ return function(form, uci)
 	function o:write(data)
 		uci:set("gluon-node-info", location, "latitude", data)
 	end
-	map.lat = o
+	if osm then
+		map.lat = o
+	end
 
 	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")
@@ -65,7 +67,9 @@ return function(form, uci)
 	function o:write(data)
 		uci:set("gluon-node-info", location, "longitude", data)
 	end
-	map.lon = o
+	if osm then
+		map.lon = o
+	end
 
 	if show_altitude then
 		o = s:option(Value, "altitude",
diff --git a/package/gluon-config-mode-hostname/luasrc/lib/gluon/config-mode/wizard/0100-hostname.lua b/package/gluon-config-mode-hostname/luasrc/lib/gluon/config-mode/wizard/0100-hostname.lua
index 53d7a1d48b2b01cc60b83ebe6fb35a4ffc48e807..1c9a0af37186deb0a3f8d027c11a279194d0370a 100644
--- a/package/gluon-config-mode-hostname/luasrc/lib/gluon/config-mode/wizard/0100-hostname.lua
+++ b/package/gluon-config-mode-hostname/luasrc/lib/gluon/config-mode/wizard/0100-hostname.lua
@@ -14,7 +14,8 @@ return function(form, uci)
 
 	local current_hostname = pretty_hostname.get(uci)
 	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 o = s:option(Value, "hostname", pkg_i18n.translate("Node name"))
diff --git a/package/gluon-core/check_site.lua b/package/gluon-core/check_site.lua
index 74a6c3f9a3252ec19b569555babf9f60f8e6019f..f953d8a17e791207bb11346614c011aeac53978b 100644
--- a/package/gluon-core/check_site.lua
+++ b/package/gluon-core/check_site.lua
@@ -39,8 +39,8 @@ for _, config in ipairs({'wifi24', 'wifi5'}) do
 		elseif config == 'wifi5' then
 			local channels = {
 				34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62,
-				64, 96, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 
-				120, 122, 124, 126, 128, 132, 134, 136, 138, 140, 142, 144, 
+				64, 96, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118,
+				120, 122, 124, 126, 128, 132, 134, 136, 138, 140, 142, 144,
 				149, 151, 153, 155, 157, 159, 161, 165, 169, 173 }
 			need_one_of({config, 'channel'}, channels)
 			need_chanlist({config, 'outdoor_chanlist'}, channels, false)
diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/020-interfaces b/package/gluon-core/luasrc/lib/gluon/upgrade/020-interfaces
index a1600a1aa3ea9d1fc1aec9286aabaf549c032d95..1e101f7024732f0a030395e1ed6fef258b540fc4 100755
--- a/package/gluon-core/luasrc/lib/gluon/upgrade/020-interfaces
+++ b/package/gluon-core/luasrc/lib/gluon/upgrade/020-interfaces
@@ -8,7 +8,6 @@ if sysconfig.lan_ifname or sysconfig.wan_ifname then
 end
 
 
-local util = require 'gluon.util'
 local platform = require 'gluon.platform'
 local site = require 'gluon.site'
 
diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/180-outdoors b/package/gluon-core/luasrc/lib/gluon/upgrade/180-outdoors
index 6ba822a334d1433daa3d13c1fbbc653ba3675f88..f9278e1f2b1d32cbdadc5f9f1ad2f5bcda0a7d35 100755
--- a/package/gluon-core/luasrc/lib/gluon/upgrade/180-outdoors
+++ b/package/gluon-core/luasrc/lib/gluon/upgrade/180-outdoors
@@ -15,7 +15,7 @@ local sysconfig = require 'gluon.sysconfig'
 local platform = require 'gluon.platform'
 
 local config = site.wifi5.outdoors('preset')
-local outdoor = false
+local outdoor
 
 if sysconfig.gluon_version then
 	-- don't enable the outdoor mode after an upgrade
diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless
index df577ea2a7c276b7f83eb46a70362f1f0f842b92..eb120404da34e69945bf575dc1686282a89ec7a3 100755
--- a/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless
+++ b/package/gluon-core/luasrc/lib/gluon/upgrade/200-wireless
@@ -16,14 +16,12 @@ if not sysconfig.gluon_version then
 	-- capable of operating in the 2.4 GHz and 5 GHz band need
 	-- to be distributed evenly.
 	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))
-		if (hwmodes.a or hwmodes.ac) and hwmodes.g then
-			-- Dualband - do nothing in this step
-		elseif hwmodes.g then
+		if hwmodes.g and not (hwmodes.a or hwmodes.ac) then
 			-- 2.4 GHz
 			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
 			radio_band_count["band5"] = radio_band_count["band5"] + 1
 		end
@@ -31,7 +29,7 @@ if not sysconfig.gluon_version then
 
 	-- Use the number of all fixed 2.4G GHz and 5 GHz radios to
 	-- 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 hwmodes = iwinfo.nl80211.hwmodelist(util.find_phy(radio))
 		if (hwmodes.a or hwmodes.ac) and hwmodes.g then
diff --git a/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg b/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg
index 51f79358512e0d1f4a1c89d83ffe4e32e574ad88..eecedaf3a414fd289c871fe0aa7a867539ba5900 100755
--- a/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg
+++ b/package/gluon-core/luasrc/lib/gluon/upgrade/500-opkg
@@ -46,7 +46,7 @@ for line in io.lines('/etc/opkg/distfeeds.conf') do
 	table.insert(distfeeds, line)
 end
 
-local f = io.open('/etc/opkg/distfeeds.conf', 'w')
+f = io.open('/etc/opkg/distfeeds.conf', 'w')
 
 for _, line in ipairs(distfeeds) do
 	local name = line:match('^src/gz%s' .. prefix .. '(%S+)%s')
@@ -62,7 +62,7 @@ end
 f:close()
 
 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
 		f:write(string.format('src/gz %s %s\n', k, replace_patterns(v)))
diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/iputil.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/iputil.lua
index bfb09a7530570aee706849738c9b2c96ae147d65..c0fe93cecb82ff7854eea70993db981d3b72bd6f 100644
--- a/package/gluon-core/luasrc/usr/lib/lua/gluon/iputil.lua
+++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/iputil.lua
@@ -85,10 +85,9 @@ function M.mac_to_ip(prefix, mac)
 	local h3 = 0x100 * m5 + tonumber(m6, 16)
 	local h4 = 0x100 * tonumber(m7, 16) + tonumber(m8, 16)
 
-	local prefix, plen = string.match(prefix, '(.*)/(%d+)')
-	plen = tonumber(plen, 10)
+	prefix = string.match(prefix, '(.*)/%d+')
 
-	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)
 end
diff --git a/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua b/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua
index 6b52f43546921ed5dc7beae9bb48f8af6a3128d5..6725958a3c3a0dbddc5644c0e49732a98da41b13 100644
--- a/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua
+++ b/package/gluon-core/luasrc/usr/lib/lua/gluon/util.lua
@@ -157,7 +157,7 @@ function M.find_phy(config)
 	end
 end
 
-local function get_addresses(uci, radio)
+local function get_addresses(radio)
 	local phy = M.find_phy(radio)
 	if not phy then
 		return function() end
@@ -200,11 +200,11 @@ function M.generate_mac(i)
 	return string.format('%02x:%s:%s:%s:%s:%02x', m1, m2, m3, m4, m5, m6)
 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 addresses = {}
-	for address in get_addresses(uci, radio) do
+	for address in get_addresses(radio) do
 		if address:lower() ~= primary then
 			table.insert(addresses, address)
 		end
@@ -222,8 +222,8 @@ local function get_wlan_mac_from_driver(uci, radio, vif)
 	end
 end
 
-function M.get_wlan_mac(uci, radio, index, vif)
-	local addr = get_wlan_mac_from_driver(uci, radio, vif)
+function M.get_wlan_mac(_, radio, index, vif)
+	local addr = get_wlan_mac_from_driver(radio, vif)
 	if addr then
 		return addr
 	end
diff --git a/package/gluon-mesh-babel/luasrc/lib/gluon/upgrade/300-gluon-mesh-babel-mkconfig b/package/gluon-mesh-babel/luasrc/lib/gluon/upgrade/300-gluon-mesh-babel-mkconfig
index c2b5cf5aa506f76c5cbbb5426e12e8a7d795a96c..e3459ffa5d2371897f657f36476b9adefd9f8b75 100755
--- a/package/gluon-mesh-babel/luasrc/lib/gluon/upgrade/300-gluon-mesh-babel-mkconfig
+++ b/package/gluon-mesh-babel/luasrc/lib/gluon/upgrade/300-gluon-mesh-babel-mkconfig
@@ -3,7 +3,7 @@
 local site = require 'gluon.site'
 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("reflect-kernel-metric true\n")
 file:write("export-table 254\n")
diff --git a/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-client-bridge b/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-client-bridge
index 85c21ac4a641191a8f96fb70a297de7e8496fe85..2f113ece907f1f6d5e257f0ecf7b99f7a84eea0a 100755
--- a/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-client-bridge
+++ b/package/gluon-mesh-batman-adv/luasrc/lib/gluon/upgrade/320-gluon-mesh-batman-adv-client-bridge
@@ -5,7 +5,6 @@
 
 
 local site = require 'gluon.site'
-local sysconfig = require 'gluon.sysconfig'
 local util = require 'gluon.util'
 local uci = require('simple-uci').cursor()
 
@@ -39,7 +38,7 @@ local networks = uci:get_list('firewall', 'mesh', 'network')
 util.add_to_set(networks, 'client')
 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')
 uci:set_list('firewall', 'drop', 'network', networks)
 
diff --git a/package/gluon-mesh-vpn-fastd/check_site.lua b/package/gluon-mesh-vpn-fastd/check_site.lua
index 18becfeecc11d5e8573acdcb1578f46b65395198..70c0d079c0d8e32a20dfce54bc9fa89b078626b6 100644
--- a/package/gluon-mesh-vpn-fastd/check_site.lua
+++ b/package/gluon-mesh-vpn-fastd/check_site.lua
@@ -2,7 +2,8 @@ local fastd_methods = {'salsa2012+gmac', 'salsa2012+umac', 'null+salsa2012+gmac'
 need_array_of({'mesh_vpn', 'fastd', 'methods'}, fastd_methods)
 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)
 	need_alphanumeric_key(k)
diff --git a/package/gluon-scheduled-domain-switch/check_site.lua b/package/gluon-scheduled-domain-switch/check_site.lua
index d1a2fa212606d35796130445a652acade3b50d38..00feec762437a00c3d75953f4cf093fa7ab424bb 100644
--- a/package/gluon-scheduled-domain-switch/check_site.lua
+++ b/package/gluon-scheduled-domain-switch/check_site.lua
@@ -1,4 +1,4 @@
-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_number(in_domain({'domain_switch', 'switch_after_offline_mins'}))
 	need_number(in_domain({'domain_switch', 'switch_time'}))
diff --git a/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/upgrade/950-gluon-scheduled-domain-switch b/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/upgrade/950-gluon-scheduled-domain-switch
index a15ed6822fc6216f0898054ccdd15d062d1f1726..c221eeda64d9a03b744cfc288404647a010fcc6d 100755
--- a/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/upgrade/950-gluon-scheduled-domain-switch
+++ b/package/gluon-scheduled-domain-switch/luasrc/lib/gluon/upgrade/950-gluon-scheduled-domain-switch
@@ -1,8 +1,6 @@
 #!/usr/bin/lua
 
-local json = require 'jsonc'
 local site = require 'gluon.site'
-local unistd = require 'posix.unistd'
 
 local cronfile = "/usr/lib/micron.d/gluon-scheduled-domain-switch"
 
diff --git a/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-switch-domain b/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-switch-domain
index 57fed15a2a4ebf380e1005aa378b8a5ad55276e9..31fcea363752db6feb17c7d63d1369b925a3a8e7 100755
--- a/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-switch-domain
+++ b/package/gluon-scheduled-domain-switch/luasrc/usr/bin/gluon-switch-domain
@@ -6,7 +6,7 @@ local util = require 'gluon.util'
 local site = require 'gluon.site'
 
 -- 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
 		return false
 	end
@@ -33,7 +33,7 @@ function switch_after_min_reached()
 end
 
 -- Returns true in case switch time has passed
-function switch_time_passed()
+local function switch_time_passed()
 	local current_time = os.time()
 	local switch_time = site.domain_switch.switch_time()
 
diff --git a/package/gluon-web-admin/luasrc/lib/gluon/config-mode/controller/admin/upgrade.lua b/package/gluon-web-admin/luasrc/lib/gluon/config-mode/controller/admin/upgrade.lua
index a4531213c5e001395902e5ab199cf53be57fa67d..9c42626d4401496966b79405e942d6f87046a751 100644
--- a/package/gluon-web-admin/luasrc/lib/gluon/config-mode/controller/admin/upgrade.lua
+++ b/package/gluon-web-admin/luasrc/lib/gluon/config-mode/controller/admin/upgrade.lua
@@ -15,10 +15,11 @@ package 'gluon-web-admin'
 local util = require 'gluon.util'
 local unistd = require 'posix.unistd'
 
+local file
 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
 		file = io.open(tmpfile, "w")
 	end
@@ -33,7 +34,6 @@ end
 local function action_upgrade(http, renderer)
 	local fcntl = require 'posix.fcntl'
 	local stat = require 'posix.sys.stat'
-	local wait = require 'posix.sys.wait'
 
 	local function fork_exec(argv)
 		local pid = unistd.fork()
@@ -63,15 +63,15 @@ local function action_upgrade(http, renderer)
 		end
 	end
 
-	local function image_supported(tmpfile)
-		return (os.execute(string.format("exec /sbin/sysupgrade -T %q >/dev/null", tmpfile)) == 0)
+	local function image_supported(supported_tmpfile)
+		return (os.execute(string.format("exec /sbin/sysupgrade -T %q >/dev/null", supported_tmpfile)) == 0)
 	end
 
 	local function storage_size()
 		local size = 0
 		if unistd.access("/proc/mtd") then
 			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
 					size = tonumber(s, 16)
 					break
@@ -79,7 +79,7 @@ local function action_upgrade(http, renderer)
 			end
 		elseif unistd.access("/proc/partitions") then
 			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
 					size = tonumber(b) * 1024
 					break
@@ -89,8 +89,8 @@ local function action_upgrade(http, renderer)
 		return size
 	end
 
-	local function image_checksum(tmpfile)
-		return (util.exec(string.format("exec sha256sum %q", tmpfile)):match("^([^%s]+)"))
+	local function image_checksum(checksum_tmpfile)
+		return (util.exec(string.format("exec sha256sum %q", checksum_tmpfile)):match("^([^%s]+)"))
 	end
 
 
diff --git a/package/gluon-web-admin/luasrc/lib/gluon/config-mode/model/admin/remote.lua b/package/gluon-web-admin/luasrc/lib/gluon/config-mode/model/admin/remote.lua
index 756b9bd1954bdfb519ce87aaf9f2a57f520e685d..da6a8a9c3e12d9a946eff802324d250bd43c7848 100644
--- a/package/gluon-web-admin/luasrc/lib/gluon/config-mode/model/admin/remote.lua
+++ b/package/gluon-web-admin/luasrc/lib/gluon/config-mode/model/admin/remote.lua
@@ -57,7 +57,7 @@ local f_password = Form(translate("Password"), translate(
 )
 f_password.reset = false
 
-local s = f_password:section(Section)
+s = f_password:section(Section)
 
 local pw1 = s:option(Value, "pw1", translate("Password"))
 pw1.password = true
diff --git a/package/gluon-web-mesh-vpn-fastd/luasrc/lib/gluon/config-mode/model/admin/mesh_vpn_fastd.lua b/package/gluon-web-mesh-vpn-fastd/luasrc/lib/gluon/config-mode/model/admin/mesh_vpn_fastd.lua
index 44f82144062d92e734f4a27a9aa16a00398de9bd..a22f0fe5afa7518ccd90afcaf01fd5f6ec589d1f 100644
--- a/package/gluon-web-mesh-vpn-fastd/luasrc/lib/gluon/config-mode/model/admin/mesh_vpn_fastd.lua
+++ b/package/gluon-web-mesh-vpn-fastd/luasrc/lib/gluon/config-mode/model/admin/mesh_vpn_fastd.lua
@@ -22,18 +22,18 @@ function mode:write(data)
 
 	-- methods will be recreated and filled with the original values from site.mesh_vpn.fastd.methods
 	-- if performance mode was selected, and the method 'null' was not present in the original table, it will be added
-	local methods = {}
+	local site_methods = {}
 	if data == 'performance' then
-		table.insert(methods, 'null')
+		table.insert(site_methods, 'null')
 	end
 
 	for _, method in ipairs(site.mesh_vpn.fastd.methods()) do
 		if method ~= 'null' then
-			table.insert(methods, method)
+			table.insert(site_methods, method)
 		end
 	end
 
-	uci:set('fastd', 'mesh_vpn', 'method', methods)
+	uci:set('fastd', 'mesh_vpn', 'method', site_methods)
 
 	uci:save('fastd')
 	uci:commit('fastd')
diff --git a/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model.lua b/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model.lua
index 5916fdcffdadca6e1f35f3c55546837f37359a73..6762b001e429f06c58d664565d859e0a42861e5e 100644
--- a/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model.lua
+++ b/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model.lua
@@ -13,7 +13,7 @@ local function load(filename, i18n)
 	local func = assert(loadfile(filename))
 
 	setfenv(func, setmetatable({}, {__index =
-		function(tbl, key)
+		function(_, key)
 			return classes[key] or i18n[key] or _G[key]
 		end
 	}))
diff --git a/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model/classes.lua b/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model/classes.lua
index 1ef61c12c78b695b4352d87ebaacd416202877ce..5af9dde45f7539f7b37d1f0ef7ad80bba11a77f9 100644
--- a/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model/classes.lua
+++ b/package/gluon-web-model/luasrc/usr/lib/lua/gluon/web/model/classes.lua
@@ -97,7 +97,7 @@ end
 function Node:resolve_depends()
 	local updated = false
 	for _, node in ipairs(self.children) do
-		update = updated or node:resolve_depends()
+		updated = updated or node:resolve_depends()
 	end
 	return updated
 end
@@ -145,7 +145,7 @@ function AbstractValue:depends(field, value)
 	table.insert(self.deps, deps)
 end
 
-function AbstractValue:deplist(section, deplist)
+function AbstractValue:deplist(_, deplist)
 	local deps = {}
 
 	for _, d in ipairs(deplist or self.deps) do
@@ -257,7 +257,8 @@ function AbstractValue:handle()
 	end
 end
 
-function AbstractValue:write(value)
+-- will be overridden: write(value)
+function AbstractValue:write()
 end
 
 
diff --git a/package/gluon-web-network/luasrc/lib/gluon/config-mode/model/admin/network.lua b/package/gluon-web-network/luasrc/lib/gluon/config-mode/model/admin/network.lua
index 7f723ee53df6105c1f28749f239b2ea0f968f66a..2d8a3a2c33c96148e47ffc3e1e2bf9ff7d13388c 100644
--- a/package/gluon-web-network/luasrc/lib/gluon/config-mode/model/admin/network.lua
+++ b/package/gluon-web-network/luasrc/lib/gluon/config-mode/model/admin/network.lua
@@ -42,7 +42,7 @@ ipv4_gateway.default = wan.gateway
 ipv4_gateway.datatype = "ip4addr"
 
 
-local s = f:section(Section)
+s = f:section(Section)
 
 local ipv6 = s:option(ListValue, "ipv6", translate("IPv6"))
 ipv6:value("dhcpv6", translate("Automatic (RA/DHCPv6)"))
@@ -61,7 +61,7 @@ ipv6_gateway.default = wan6.ip6gw
 ipv6_gateway.datatype = "ip6addr"
 
 if dns_static then
-	local s = f:section(Section)
+	s = f:section(Section)
 
 	local dns = s:option(DynamicList, "dns", translate("Static DNS servers"))
 	dns.default = uci:get_list("gluon-wan-dnsmasq", dns_static, "server")
@@ -74,7 +74,7 @@ if dns_static then
 	end
 end
 
-local s = f:section(Section)
+s = f:section(Section)
 
 local mesh_wan = s:option(Flag, "mesh_wan", translate("Enable meshing on the WAN interface"))
 mesh_wan.default = not uci:get_bool("network", "mesh_wan", "disabled")
@@ -84,7 +84,7 @@ function mesh_wan:write(data)
 end
 
 if sysconfig.lan_ifname then
-	local s = f:section(Section)
+	s = f:section(Section)
 
 	local mesh_lan = s:option(Flag, "mesh_lan", translate("Enable meshing on the LAN interface"))
 	mesh_lan.default = not uci:get_bool("network", "mesh_lan", "disabled")
@@ -107,24 +107,24 @@ if sysconfig.lan_ifname then
 end
 
 local section
-uci:foreach("system", "gpio_switch", function(s)
-	if s[".name"]:match("poe") then
+uci:foreach("system", "gpio_switch", function(si)
+	if si[".name"]:match("poe") then
 		if not section then
 			section = f:section(Section)
 		end
 
-		local port = s.name:match("^PoE Power Port(%d*)$")
+		local port = si.name:match("^PoE Power Port(%d*)$")
 		local name
 		if port then
 			name = translatef("Enable PoE Power Port %s", port)
 		else
-			name = translate("Enable " .. s.name)
+			name = translate("Enable " .. si.name)
 		end
-		local poe = section:option(Flag, s[".name"], name)
-		poe.default = uci:get_bool("system", s[".name"], "value")
+		local poe = section:option(Flag, si[".name"], name)
+		poe.default = uci:get_bool("system", si[".name"], "value")
 
 		function poe:write(data)
-			uci:set("system", s[".name"], "value", data)
+			uci:set("system", si[".name"], "value", data)
 		end
 	end
 end)
diff --git a/package/gluon-web-node-role/luasrc/lib/gluon/config-mode/model/admin/noderole.lua b/package/gluon-web-node-role/luasrc/lib/gluon/config-mode/model/admin/noderole.lua
index 3419e6281be90ee60d37a8a59be9f81bda9cd8bf..9d610663b74c849ec263a5bf35bf2f69c330fe8c 100644
--- a/package/gluon-web-node-role/luasrc/lib/gluon/config-mode/model/admin/noderole.lua
+++ b/package/gluon-web-node-role/luasrc/lib/gluon/config-mode/model/admin/noderole.lua
@@ -17,8 +17,8 @@ s = f:section(Section, nil, translate(
 
 o = s:option(ListValue, "role", translate("Role"))
 o.default = role
-for _, role in ipairs(site.roles.list()) do
-	o:value(role, site_i18n.translate('gluon-web-node-role:role:' .. role))
+for _, role_value in ipairs(site.roles.list()) do
+	o:value(role, site_i18n.translate('gluon-web-node-role:role:' .. role_value))
 end
 
 function o:write(data)
diff --git a/package/gluon-web-wifi-config/luasrc/lib/gluon/config-mode/model/admin/wifi-config.lua b/package/gluon-web-wifi-config/luasrc/lib/gluon/config-mode/model/admin/wifi-config.lua
index fc3b231974aa7eab23fe15a7ace157da46c10117..80e6dfafe35e33a3ac5f1f858637b576b7af4731 100644
--- a/package/gluon-web-wifi-config/luasrc/lib/gluon/config-mode/model/admin/wifi-config.lua
+++ b/package/gluon-web-wifi-config/luasrc/lib/gluon/config-mode/model/admin/wifi-config.lua
@@ -1,5 +1,4 @@
 local iwinfo = require 'iwinfo'
-local site = require 'gluon.site'
 local uci = require("simple-uci").cursor()
 local util = require 'gluon.util'
 
@@ -158,7 +157,7 @@ end
 
 function f:write()
 	uci:commit('gluon')
-	os.execute('/lib/gluon/upgrade/200-wireless') 
+	os.execute('/lib/gluon/upgrade/200-wireless')
 	uci:commit('wireless')
 end
 
diff --git a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/dispatcher.lua b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/dispatcher.lua
index 7f5b4c8b1f3f7f5c945332fe9e50c50e167dc9a2..2d72777661b2d9a6f565e4836129c7bf3d23ad37 100644
--- a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/dispatcher.lua
+++ b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/dispatcher.lua
@@ -109,8 +109,8 @@ local function dispatch(config, http, request)
 					return _node({...})
 				end,
 
-				entry = function(path, target, title, order)
-					local c = _node(path, true)
+				entry = function(entry_path, target, title, order)
+					local c = _node(entry_path, true)
 
 					c.target = target
 					c.title  = title
@@ -204,7 +204,7 @@ return function(config, http)
 		table.insert(request, node)
 	end
 
-	ok, err = pcall(dispatch, config, http, request)
+	local ok, err = pcall(dispatch, config, http, request)
 	if not ok then
 		http:status(500, "Internal Server Error")
 		http:prepare_content("text/plain")
diff --git a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/http.lua b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/http.lua
index 127a492ac5c9ee6d472dc7c2f41f78f04a61c41c..c77d4ace01ea44face7f07b6e11340b29c80ae40 100644
--- a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/http.lua
+++ b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/http.lua
@@ -53,7 +53,7 @@ end
 function Http:getcookie(name)
 	local c = string.gsub(";" .. (self:getenv("HTTP_COOKIE") or "") .. ";", "%s*;%s*", ";")
 	local p = ";" .. name .. "=(.-);"
-	local i, j, value = c:find(p)
+	local _, _, value = c:find(p)
 	return value and protocol.urldecode(value)
 end
 
diff --git a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/http/protocol.lua b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/http/protocol.lua
index 48797b6a0ce0e4d0a2e7e48d4c64ab8f5aad9303..8d070d951d3cd3d48c4a5c38fe1c05a5027227a8 100644
--- a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/http/protocol.lua
+++ b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/http/protocol.lua
@@ -124,13 +124,13 @@ local function mimedecode_message_body(src, msg, filecb)
 	local store  = nil
 	local lchunk = nil
 
-	local function parse_headers(chunk, field)
+	local function parse_headers(chunk, pfield)
 		local stat
 		repeat
 			chunk, stat = chunk:gsub(
 				"^([A-Z][A-Za-z0-9%-_]+): +([^\r\n]+)\r\n",
 				function(k,v)
-					field.headers[k] = v
+					pfield.headers[k] = v
 					return ""
 				end
 			)
@@ -140,26 +140,26 @@ local function mimedecode_message_body(src, msg, filecb)
 
 		-- End of headers
 		if stat > 0 then
-			if field.headers["Content-Disposition"] then
-				if field.headers["Content-Disposition"]:match("^form%-data; ") then
-					field.name = field.headers["Content-Disposition"]:match('name="(.-)"')
-					field.file = field.headers["Content-Disposition"]:match('filename="(.+)"$')
+			if pfield.headers["Content-Disposition"] then
+				if pfield.headers["Content-Disposition"]:match("^form%-data; ") then
+					pfield.name = pfield.headers["Content-Disposition"]:match('name="(.-)"')
+					pfield.file = pfield.headers["Content-Disposition"]:match('filename="(.+)"$')
 				end
 			end
 
-			if not field.headers["Content-Type"] then
-				field.headers["Content-Type"] = "text/plain"
+			if not pfield.headers["Content-Type"] then
+				pfield.headers["Content-Type"] = "text/plain"
 			end
 
 
-			if field.name then
-				initval(msg.params, field.name)
-				if field.file then
-					appendval(msg.params, field.name, field.file)
+			if pfield.name then
+				initval(msg.params, pfield.name)
+				if pfield.file then
+					appendval(msg.params, pfield.name, pfield.file)
 					store = filecb
 				else
-					store = function(hdr, buf, eof)
-						appendval(msg.params, field.name, buf)
+					store = function(_, buf, _)
+						appendval(msg.params, pfield.name, buf)
 					end
 				end
 			else
@@ -197,6 +197,7 @@ local function mimedecode_message_body(src, msg, filecb)
 
 				if spos then
 					local predata = data:sub(1, spos - 1)
+					local eof
 
 					if inhdr then
 						predata, eof = parse_headers(predata, field)
@@ -225,11 +226,12 @@ local function mimedecode_message_body(src, msg, filecb)
 				-- We found at least some boundary. Save
 				-- the unparsed remaining data for the
 				-- next chunk.
-				lchunk, data = data, nil
+				lchunk = data
 			else
 				-- There was a complete chunk without a boundary. Parse it as headers or
 				-- append it as data, depending on our current state.
 				if inhdr then
+					local eof
 					lchunk, eof = parse_headers(data, field)
 					inhdr = not eof
 				else
@@ -240,7 +242,7 @@ local function mimedecode_message_body(src, msg, filecb)
 					if store then
 						store(field, lchunk, false)
 					end
-					lchunk, chunk = chunk, nil
+					lchunk = chunk
 				end
 			end
 		end
diff --git a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/i18n.lua b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/i18n.lua
index 80424505b95dd82144b4a0ad25668adf5cd6dc07..92dd2e5505ad3d7e12cd606bff5f9e479fc68d27 100644
--- a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/i18n.lua
+++ b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/i18n.lua
@@ -13,7 +13,7 @@ return function(config)
 		return string.format('%s/%s.%s.lmo', i18ndir, pkg, lang)
 	end
 
-	local function no_translation(key)
+	local function no_translation()
 		return nil
 	end
 
diff --git a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/template.lua b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/template.lua
index 181400334aee3fcc9e9753b5c28202c7acff27f7..1f5bbd4c3bcc884c7c57a3ca820d97dbada4fed6 100644
--- a/package/gluon-web/luasrc/usr/lib/lua/gluon/web/template.lua
+++ b/package/gluon-web/luasrc/usr/lib/lua/gluon/web/template.lua
@@ -44,13 +44,13 @@ return function(config, env)
 			translate = t.translate,
 			translatef = t.translatef,
 			_translate = t._translate,
-			include = function(name)
-				ctx.render(name, scope, pkg)
+			include = function(include_name)
+				ctx.render(include_name, scope, pkg)
 			end,
 		}
 
 		setfenv(template, setmetatable({}, {
-			__index = function(tbl, key)
+			__index = function(_, key)
 				return scope[key] or locals[key] or env[key]
 			end
 		}))
diff --git a/scripts/check_site.lua b/scripts/check_site.lua
index d4a9b571a61d90e0f23bcdaddd63d9f8a84cc9dc..3f26a584f71d3fa6431dc6bd9afd10a90b2ad6d2 100644
--- a/scripts/check_site.lua
+++ b/scripts/check_site.lua
@@ -37,7 +37,7 @@ local site, domain_code, domain, conf
 local function merge(a, b)
 	local function is_array(t)
 		local n = 0
-		for k, v in pairs(t) do
+		for _ in pairs(t) do
 			n = n + 1
 		end
 		return n == #t
@@ -216,12 +216,12 @@ local function check_chanlist(channels)
 	return function(chanlist)
 		for group in chanlist:gmatch("%S+") do
 			if group:match("^%d+$") then
-				channel = tonumber(group)
+				local channel = tonumber(group)
 				if not is_valid_channel(channel) then
 					return false
 				end
 			elseif group:match("^%d+-%d+$") then
-				from, to = group:match("^(%d+)-(%d+)$")
+				local from, to = group:match("^(%d+)-(%d+)$")
 				from = tonumber(from)
 				to = tonumber(to)
 				if from >= to then
@@ -344,8 +344,9 @@ end
 
 function need_chanlist(path, channels, required)
 	local valid_chanlist = check_chanlist(channels)
-	return need(path, valid_chanlist, required, 'be a space-separated list of WiFi channels or channel-ranges (separated by a hyphen). ' .. 
-	'Valid channels are: ' .. array_to_string(channels))
+	return need(path, valid_chanlist, required,
+		'be a space-separated list of WiFi channels or channel-ranges (separated by a hyphen). '
+		.. 'Valid channels are: ' .. array_to_string(channels))
 end
 
 function need_domain_name(path)