0d9c6cf15ebba0ab53a75c2e44d202655ee3c4c1
[openwrt/openwrt.git] / package / uci / trigger / apply_config
1 #!/usr/bin/lua
2 require("uci")
3 require("uci.trigger")
4
5 function usage()
6 print("Usage: " .. arg[0] .. " [options]")
7 print("Options:")
8 print(" -a: apply the config changes")
9 print(" -t: show matching UCI triggers")
10 print(" -s: show information about tasks to be executed")
11 print(" -r: reset all triggers")
12 print("")
13 end
14
15 if arg[1] == "-s" then
16 local triggers = uci.trigger.get_active()
17 if #triggers > 0 then
18 print("Tasks:")
19 for i, a in ipairs(triggers) do
20 local trigger = a[1]
21 local sections = a[2]
22 print(" - " .. uci.trigger.get_description(trigger, sections))
23 end
24 else
25 print "Nothing to do"
26 end
27 elseif arg[1] == "-t" then
28 local triggers = uci.trigger.get_active()
29 for i, a in ipairs(triggers) do
30 local trigger = a[1]
31 local sections = a[2]
32 if trigger.section_only then
33 print(trigger.id .. " " .. table.concat(" ", sections))
34 else
35 print(trigger.id)
36 end
37 end
38 elseif arg[1] == "-a" then
39 uci.trigger.run()
40 elseif arg[1] == "-r" then
41 uci.trigger.reset_state()
42 else
43 usage()
44 end