2009-06-08 01:27:01 +00:00
|
|
|
#!/usr/bin/lua
|
|
|
|
require("uci")
|
|
|
|
require("uci.trigger")
|
|
|
|
|
|
|
|
function usage()
|
|
|
|
print("Usage: " .. arg[0] .. " [options]")
|
|
|
|
print("Options:")
|
|
|
|
print(" -a: apply the config changes")
|
|
|
|
print(" -t: show matching UCI triggers")
|
|
|
|
print(" -s: show information about tasks to be executed")
|
|
|
|
print(" -r: reset all triggers")
|
2009-07-06 19:04:07 +00:00
|
|
|
print(" -C <trigger> [<section>]: force clear a trigger")
|
|
|
|
print(" -S <trigger> [<section>]: force set a trigger")
|
2009-06-08 01:27:01 +00:00
|
|
|
print("")
|
|
|
|
end
|
|
|
|
|
|
|
|
if arg[1] == "-s" then
|
|
|
|
local triggers = uci.trigger.get_active()
|
|
|
|
if #triggers > 0 then
|
|
|
|
print("Tasks:")
|
|
|
|
for i, a in ipairs(triggers) do
|
|
|
|
local trigger = a[1]
|
|
|
|
local sections = a[2]
|
|
|
|
print(" - " .. uci.trigger.get_description(trigger, sections))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print "Nothing to do"
|
|
|
|
end
|
|
|
|
elseif arg[1] == "-t" then
|
|
|
|
local triggers = uci.trigger.get_active()
|
|
|
|
for i, a in ipairs(triggers) do
|
|
|
|
local trigger = a[1]
|
|
|
|
local sections = a[2]
|
|
|
|
if trigger.section_only then
|
2009-08-04 00:43:55 +00:00
|
|
|
print(trigger.id .. " " .. table.concat(sections, " "))
|
2009-06-08 01:27:01 +00:00
|
|
|
else
|
|
|
|
print(trigger.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif arg[1] == "-a" then
|
|
|
|
uci.trigger.run()
|
|
|
|
elseif arg[1] == "-r" then
|
|
|
|
uci.trigger.reset_state()
|
2009-07-06 19:04:07 +00:00
|
|
|
elseif arg[1] == "-S" then
|
|
|
|
local trigger = arg[2]
|
|
|
|
local section = arg[3]
|
|
|
|
uci.trigger.set_active(trigger, section)
|
|
|
|
elseif arg[1] == "-C" then
|
|
|
|
local trigger = arg[2]
|
|
|
|
local section = arg[3]
|
|
|
|
uci.trigger.clear_active(trigger, section)
|
2009-06-08 01:27:01 +00:00
|
|
|
else
|
|
|
|
usage()
|
|
|
|
end
|