Skip to content

Commit e945df2

Browse files
author
Bob Ham
committed
config: Call hotplug hooks in more places
Also add an ACTION environment variable containing the same value as passed as a command-line argument. Some scripts presume they will only be called in the one existing place so they need to be updated also.
1 parent a9488ae commit e945df2

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

packages/babeld-auto-gw-mode/files/etc/hotplug.d/lime-config/babeld-auto-gw.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/lua
22

3+
if os.getenv("ACTION") ~= "post" then
4+
return
5+
end
6+
37
local config = require("lime.config")
48
local uci = config.get_uci_cursor()
59

packages/lime-system/files/usr/lib/lua/lime/config.lua

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,27 @@ function config.uci_commit_all()
182182
end
183183
end
184184

185+
function config.execute_hooks(action)
186+
for hook in fs.dir(config.hooksDir) do
187+
local hookCmd = config.hooksDir.."/"..hook
188+
local shCmd = "sh -c 'ACTION="..action.." "..hookCmd.."'"
189+
print("Executed hook:", shCmd, os.execute(shCmd))
190+
end
191+
end
192+
193+
--! FIXME: This should be somewhere more appropriate
194+
function config.file_exists(name)
195+
return fs.stat(name, "type") == "reg"
196+
end
197+
185198
function config.main()
199+
--! Check whether this is the first ever run
200+
if not config.file_exists(config.uci:get_confdir() .. "/" .. config.UCI_AUTOGEN_NAME) then
201+
config.execute_hooks("init")
202+
end
203+
204+
config.execute_hooks("pre")
205+
186206
--! Get mac address and set mac-based configuration file name
187207
local network = require("lime.network")
188208
local utils = require("lime.utils")
@@ -193,16 +213,15 @@ function config.main()
193213
--! Populate the default template configs if lime-node and lime-community
194214
--! are not found in /etc/config
195215
for _, cfg_name in pairs({config.UCI_COMMUNITY_NAME, config.UCI_NODE_NAME}) do
196-
local lime_path = config.uci:get_confdir() .. "/" .. cfg_name
197-
local cf = io.open(lime_path)
198-
if not cf then
216+
local lime_path = config.uci:get_confdir() .. "/" .. cfg_name
217+
if not config.file_exists(lime_path) then
199218
config.initialize_config_file(cfg_name)
200-
else
201-
cf:close()
202219
end
203220
end
204221
config.uci_autogen()
205222

223+
config.execute_hooks("merged")
224+
206225
local modules_name = { "hardware_detection", "wireless", "network", "firewall", "system",
207226
"generic_config" }
208227

@@ -221,10 +240,7 @@ function config.main()
221240
xpcall(module.configure, function(errmsg) print(errmsg) ; print(debug.traceback()) end)
222241
end
223242

224-
for hook in fs.dir(config.hooksDir) do
225-
local hookCmd = config.hooksDir.."/"..hook.." after"
226-
print("executed hook:", hookCmd, os.execute(hookCmd))
227-
end
243+
config.execute_hooks("configured")
228244

229245
local cfgpath = config.get_config_path()
230246
--! flush all config changes
@@ -235,6 +251,8 @@ function config.main()
235251
'# Instead please edit /etc/config/lime-node and/or /etc/config/lime-community files\n' ..
236252
'# and then regenerate this file executing lime-config\n\n')
237253
utils.write_file(cfgpath, notice_message .. autogen_content)
254+
255+
config.execute_hooks("post")
238256
end
239257

240258
return config

0 commit comments

Comments
 (0)