Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/lua

if os.getenv("ACTION") ~= "post" then
return
end

local config = require("lime.config")
local uci = config.get_uci_cursor()

Expand Down
36 changes: 27 additions & 9 deletions packages/lime-system/files/usr/lib/lua/lime/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,27 @@ function config.uci_commit_all()
end
end

function config.execute_hooks(action)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function or something very similar feels like to be used/needed in more place in LiMe code, let's try to avoid duplication

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting the function should be moved? If so, where would you suggest it be moved to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this function is relevant not just to the config module, but to any module that might want to run some hook (all). In fact I am surprised that something similar doesn't already exists, have you double checked?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you double checked?

I haven't single checked :-) I'm not sure what your expectation is here. What do you expect me to have checked? Bearing in mind I don't know either the codebase or Lua well at all. Can you tell me where you would expect me to check?

for hook in fs.dir(config.hooksDir) do
local hookCmd = config.hooksDir.."/"..hook
local shCmd = "sh -c 'ACTION="..action.." "..hookCmd.."'"
print("Executed hook:", shCmd, os.execute(shCmd))
end
end

--! FIXME: This should be somewhere more appropriate
function config.file_exists(name)
return fs.stat(name, "type") == "reg"
end

function config.main()
--! Check whether this is the first ever run
if not config.file_exists(config.uci:get_confdir() .. "/" .. config.UCI_AUTOGEN_NAME) then
config.execute_hooks("init")
end

config.execute_hooks("pre")

--! Get mac address and set mac-based configuration file name
local network = require("lime.network")
local utils = require("lime.utils")
Expand All @@ -193,16 +213,15 @@ function config.main()
--! Populate the default template configs if lime-node and lime-community
--! are not found in /etc/config
for _, cfg_name in pairs({config.UCI_COMMUNITY_NAME, config.UCI_NODE_NAME}) do
local lime_path = config.uci:get_confdir() .. "/" .. cfg_name
local cf = io.open(lime_path)
if not cf then
local lime_path = config.uci:get_confdir() .. "/" .. cfg_name
if not config.file_exists(lime_path) then
config.initialize_config_file(cfg_name)
else
cf:close()
end
end
config.uci_autogen()

config.execute_hooks("merged")

local modules_name = { "hardware_detection", "wireless", "network", "firewall", "system",
"generic_config" }

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

for hook in fs.dir(config.hooksDir) do
local hookCmd = config.hooksDir.."/"..hook.." after"
print("executed hook:", hookCmd, os.execute(hookCmd))
end
config.execute_hooks("configured")

local cfgpath = config.get_config_path()
--! flush all config changes
Expand All @@ -235,6 +251,8 @@ function config.main()
'# Instead please edit /etc/config/lime-node and/or /etc/config/lime-community files\n' ..
'# and then regenerate this file executing lime-config\n\n')
utils.write_file(cfgpath, notice_message .. autogen_content)

config.execute_hooks("post")
end

return config